Gevorderde DAX in Power BI
Carl Rosseel
Curriculum Manager
Logische functies werken op een expressie en geven info over de waarden of sets erin.
De meest gebruikte logische functies:
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 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 minimaal één voorwaarde TRUE isOR(5 < 4, 5 < 6) = OR(FALSE, TRUE) = TRUENOT(<logical>)TRUE en FALSE omNOT(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 waarden en geeft één van meerdere mogelijke resultaten 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% |
Gevorderde DAX in Power BI