leb1_14
¡Hola!
Soy nuevo en Power BI y me pregunto si es posible contar la cantidad de elementos coincidentes entre dos columnas. Por ejemplo, tengo una tabla que se parece a esto:
IDENTIFICACIÓN | Objeto 1 | Item2 |
1 | Plátano | manzana |
2 | Durazno | manzana |
3 | manzana | naranja |
4 | Plátano | naranja |
5 | naranja | manzana |
El problema es que quiero saber cuántas manzanas hay en total, cuántas bananas hay en total, cuántos melocotones hay en total, etc. No sé si hay una manera de hacerlo de forma dinámica (sin tener que especificar el nombre del elemento) y luego calcularlo todo en la misma consulta.
Greg_Deckler
Claro, debería poder hacer esto, aunque el código DAX exacto variará dependiendo de lo que esté tratando de lograr específicamente, pero como cálculo de columna, se vería algo así como:
Columna = VAR __table = FILTER (ALL ('Table'),[Item1] = ANTES ('Tabla'[Item1))) VAR __table1 = FILTER(ALL('Table'),[Item2] = ANTES ('Tabla'[Item1)) RETURN COUNTROWS(__table) + COUNTROWS (__table1)
Something along those lines. The above code should give you the total count of the current value of Item1 in your row for both Item1 and Item2 columns assuming I didn’t miss a paren or something because I didn’t test it.
leb1_14
In response to Greg_Deckler
Actually, I modified the query a bit by adding the column as well.
Column = VAR __table = FILTER(ALL('Table'[Item1]),[Item1] = ANTES ('Tabla'[Item1])) VAR __table1 = FILTER (ALL ('Tabla'[Item2]),[Item2] = ANTES ('Tabla'[Item1])) REGRESAR COUNTROWS (__ tabla) + COUNTROWS (__table1)
Gracias por eso, ¡ayudó!
Aunque tengo otra pregunta. ¿Hay alguna forma de fusionar las tablas y calcular un recuento distinto?
Greg_Deckler
Claro, debería poder hacer esto, aunque el código DAX exacto variará dependiendo de lo que esté tratando de lograr específicamente, pero como cálculo de columna, se vería algo así como:
Columna = VAR __table = FILTER (ALL ('Table'),[Item1] = ANTES ('Tabla'[Item1))) VAR __table1 = FILTER(ALL('Table'),[Item2] = ANTES ('Tabla'[Item1)) RETURN COUNTROWS(__table) + COUNTROWS (__table1)
Something along those lines. The above code should give you the total count of the current value of Item1 in your row for both Item1 and Item2 columns assuming I didn’t miss a paren or something because I didn’t test it.
leb1_14
In response to Greg_Deckler
Actually, I modified the query a bit by adding the column as well.
Column = VAR __table = FILTER(ALL('Table'[Item1]),[Item1] = ANTES ('Tabla'[Item1])) VAR __table1 = FILTER (ALL ('Tabla'[Item2]),[Item2] = ANTES ('Tabla'[Item1])) REGRESAR COUNTROWS (__ tabla) + COUNTROWS (__table1)
Gracias por eso, ¡ayudó!
Aunque tengo otra pregunta. ¿Hay alguna forma de fusionar las tablas y calcular un recuento distinto?