DAX intermedio en Power BI
Carl Rosseel
Curriculum Manager
Las funciones lógicas actúan sobre una expresión para devolver información sobre los valores o conjuntos en ella.
Las más usadas son:
IF()AND(), OR(), NOT()SWITCH()Estructura:
IF(<logical_test>, <value_if_true>, <value_if_false>)Ejemplo:
Performance = IF([Total Sales] >= 50 000, "Target Reached", "Target Not Reached")Estructura:
IF(<logical_test>, <value_if_true>[, <value_if_false>])Ejemplo:
Performance = IF([Total Sales] >= 50 000, "Target Reached", "Target Not Reached") | Nombre | Ventas totales |
|---|---|
| Jenny | 48,431 |
| Jane | 76,528 |
| Dwayne | 24,167 |
| Thomas | 52,125 |
Estructura:
IF(<logical_test>, <value_if_true>[, <value_if_false>])Ejemplo:
Performance = IF([Total_Sales] >= 50 000, "Target Reached", "Target Not Reached")| Nombre | Ventas totales | Desempeño |
|---|---|---|
| Jenny | 48,431 | Objetivo no alcanzado |
| Jane | 76,528 | Objetivo alcanzado |
| Dwayne | 24,167 | Objetivo no alcanzado |
| Thomas | 52,125 | Objetivo alcanzado |
Los tres operadores devuelven TRUE o FALSE.
AND(<logical1>,<logical2>)TRUE si ambas condiciones son TRUEAND(5 < 4, 5 < 6) = AND(FALSE, TRUE) = FALSEOR(<logical1>,<logical2>)TRUE si al menos una condición es TRUEOR(5 < 4, 5 < 6) = OR(FALSE, TRUE) = TRUENOT(<logical>)TRUE a FALSE y viceversaNOT(OR(5 < 4, 5 < 6)) = NOT(TRUE) = FALSEAND se puede reemplazar por &&
AND(5 < 4, 5 < 6) = 5 < 4 && 5 < 6 OR se puede reemplazar por ||
OR(5 < 4, 5 < 6) = 5 < 4 || 5 < 6Evalúa una expresión frente a una lista de valores y devuelve uno de varios posibles resultados.
SWITCH(<expression>, <value>, <result>[, <value>, <result>] ... [, <else>])IF() anidadosPerformance = SWITCH(TRUE,
[Total_Sales] < 25 000, "Poor",
[Total_Sales] < 50 000, "Below expectations",
[Total_Sales] < 75 000, "Above expectations",
"Exceptional")
Performance = SWITCH(TRUE,
[Total_Sales] < 25 000, "Poor",
[Total_Sales] < 50 000, "Below expectations",
[Total_Sales] < 75 000, "Above expectations",
"Exceptional")
| Nombre | Ventas totales |
|---|---|
| Jenny | 48,431 |
| Jane | 76,528 |
| Dwayne | 24,167 |
| Thomas | 52,125 |
Performance = SWITCH(TRUE,
[Total_Sales] < 25 000, "Poor",
[Total_Sales] < 50 000, "Below expectations",
[Total_Sales] < 75 000, "Above expectations",
"Exceptional")
| Nombre | Ventas totales | Desempeño |
|---|---|---|
| Jenny | 48,431 | Por debajo de lo esperado |
| Jane | 76,528 | Excepcional |
| Dwayne | 24,167 | Pobre |
| Thomas | 52,125 | Por encima de lo esperado |
DISCOUNT = SWITCH([Clothing Type],
"Shoes", 0.15,
"Pants", 0.20,
"Belts", 0.30,
"T-shirt", 0.25)
| Tipo de prenda |
|---|
| Shoes |
| Pants |
| Belt |
| T-shirt |
DISCOUNT = SWITCH([Clothing Type],
"Shoes", 0.15,
"Pants", 0.20,
"Belts", 0.30,
"T-shirt", 0.25)
| Tipo de prenda | Descuento |
|---|---|
| Shoes | 15% |
| Pants | 20% |
| Belt | 30% |
| T-shirt | 25% |
DAX intermedio en Power BI