DAX intermedio in Power BI
Carl Rosseel
Curriculum Manager
Le funzioni logiche agiscono su un’espressione per restituire informazioni sui valori o sui set nell’espressione.
Le funzioni logiche più usate sono:
IF()AND(), OR(), NOT()SWITCH()Struttura:
IF(<logical_test>, <value_if_true>, <value_if_false>)Esempio:
Performance = IF([Total Sales] >= 50 000, "Target Reached", "Target Not Reached")Struttura:
IF(<logical_test>, <value_if_true>[, <value_if_false>])Esempio:
Performance = IF([Total Sales] >= 50 000, "Target Reached", "Target Not Reached") | Nome | Vendite totali |
|---|---|
| Jenny | 48,431 |
| Jane | 76,528 |
| Dwayne | 24,167 |
| Thomas | 52,125 |
Struttura:
IF(<logical_test>, <value_if_true>[, <value_if_false>])Esempio:
Performance = IF([Total_Sales] >= 50 000, "Target Reached", "Target Not Reached")| Nome | Vendite totali | Performance |
|---|---|---|
| Jenny | 48,431 | Target non raggiunto |
| Jane | 76,528 | Target raggiunto |
| Dwayne | 24,167 | Target non raggiunto |
| Thomas | 52,125 | Target raggiunto |
Tutti e tre gli operatori restituiscono TRUE o FALSE.
AND(<logical1>,<logical2>)TRUE se entrambe le condizioni sono TRUEAND(5 < 4, 5 < 6) = AND(FALSE, TRUE) = FALSEOR(<logical1>,<logical2>)TRUE se almeno una condizione è TRUEOR(5 < 4, 5 < 6) = OR(FALSE, TRUE) = TRUENOT(<logical>)TRUE in FALSE e viceversaNOT(OR(5 < 4, 5 < 6)) = NOT(TRUE) = FALSEAND può essere scritto anche &&
AND(5 < 4, 5 < 6) = 5 < 4 && 5 < 6 OR può essere scritto anche ||
OR(5 < 4, 5 < 6) = 5 < 4 || 5 < 6Valuta un’espressione su un elenco di valori e restituisce uno dei possibili risultati.
SWITCH(<expression>, <value>, <result>[, <value>, <result>] ... [, <else>])IF() annidatiPerformance = 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")
| Nome | Vendite totali |
|---|---|
| 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")
| Nome | Vendite totali | Performance |
|---|---|---|
| Jenny | 48,431 | Sotto le aspettative |
| Jane | 76,528 | Eccezionale |
| Dwayne | 24,167 | Scarsa |
| Thomas | 52,125 | Sopra le aspettative |
DISCOUNT = SWITCH([Clothing Type],
"Shoes", 0.15,
"Pants", 0.20,
"Belts", 0.30,
"T-shirt", 0.25)
| Tipo di abbigliamento |
|---|
| Shoes |
| Pants |
| Belt |
| T-shirt |
DISCOUNT = SWITCH([Clothing Type],
"Shoes", 0.15,
"Pants", 0.20,
"Belts", 0.30,
"T-shirt", 0.25)
| Tipo di abbigliamento | Sconto |
|---|---|
| Shoes | 15% |
| Pants | 20% |
| Belt | 30% |
| T-shirt | 25% |
DAX intermedio in Power BI