DAX voor gevorderden in Power BI
Carl Rosseel
Curriculum Manager
Logische functies evalueren een expressie en geven info over de waarden of reeksen in die expressie.
De meest gebruikte logische functies zijn:
IF()AND(), OR(), NOT()SWITCH()Structuur:
IF(<logical_test>, <value_if_true>, <value_if_false>)Voorbeeld:
Performance = IF([Total Sales] >= 50 000, "Target Reached", "Target Not Reached")Structuur:
IF(<logical_test>, <value_if_true>[, <value_if_false>])Voorbeeld:
Performance = IF([Total Sales] >= 50 000, "Target Reached", "Target Not Reached") | Naam | Total Sales |
|---|---|
| Jenny | 48,431 |
| Jane | 76,528 |
| Dwayne | 24,167 |
| Thomas | 52,125 |
Structuur:
IF(<logical_test>, <value_if_true>[, <value_if_false>])Voorbeeld:
Performance = IF([Total_Sales] >= 50 000, "Target Reached", "Target Not Reached")| Naam | Total Sales | Performance |
|---|---|---|
| Jenny | 48,431 | Target Not Reached |
| Jane | 76,528 | Target Reached |
| Dwayne | 24,167 | Target Not Reached |
| Thomas | 52,125 | Target Reached |
Alle drie de operatoren geven TRUE of FALSE terug.
AND(<logical1>,<logical2>)TRUE als beide voorwaarden TRUE zijnAND(5 < 4, 5 < 6) = AND(FALSE, TRUE) = FALSEOR(<logical1>,<logical2>)TRUE als minstens één voorwaarde TRUE isOR(5 < 4, 5 < 6) = OR(FALSE, TRUE) = TRUENOT(<logical>)TRUE in FALSE en omgekeerdNOT(OR(5 < 4, 5 < 6)) = NOT(TRUE) = FALSEAND kan worden vervangen door &&
AND(5 < 4, 5 < 6) = 5 < 4 && 5 < 6 OR kan worden vervangen door ||
OR(5 < 4, 5 < 6) = 5 < 4 || 5 < 6Evalueert een expressie tegen een lijst met waarden en geeft een van meerdere mogelijke resultaat-expressies terug.
SWITCH(<expression>, <value>, <result>[, <value>, <result>] ... [, <else>])IF()-functiesPerformance = 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")
| Naam | Total Sales |
|---|---|
| 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")
| Naam | Total Sales | Performance |
|---|---|---|
| Jenny | 48,431 | Below Expectations |
| Jane | 76,528 | Exceptional |
| Dwayne | 24,167 | Poor |
| Thomas | 52,125 | Above expectations |
DISCOUNT = SWITCH([Clothing Type],
"Shoes", 0.15,
"Pants", 0.20,
"Belts", 0.30,
"T-shirt", 0.25)
| Clothing Type |
|---|
| Shoes |
| Pants |
| Belt |
| T-shirt |
DISCOUNT = SWITCH([Clothing Type],
"Shoes", 0.15,
"Pants", 0.20,
"Belts", 0.30,
"T-shirt", 0.25)
| Clothing Type | Discount |
|---|---|
| Shoes | 15% |
| Pants | 20% |
| Belt | 30% |
| T-shirt | 25% |
DAX voor gevorderden in Power BI