DAX intermediar în Power BI
Carl Rosseel
Curriculum Manager
Funcțiile logice acționează asupra unei expresii pentru a returna informații despre valorile sau seturile din expresie.
Cele mai utilizate funcții logice sunt:
IF()AND(), OR(), NOT()SWITCH()Structură:
IF(<logical_test>, <value_if_true>, <value_if_false>)Exemplu:
Performance = IF([Total Sales] >= 50 000, "Target Reached", "Target Not Reached")Structură:
IF(<logical_test>, <value_if_true>[, <value_if_false>])Exemplu:
Performance = IF([Total Sales] >= 50 000, "Target Reached", "Target Not Reached") | Nume | Vânzări totale |
|---|---|
| Jenny | 48.431 |
| Jane | 76.528 |
| Dwayne | 24.167 |
| Thomas | 52.125 |
Structură:
IF(<logical_test>, <value_if_true>[, <value_if_false>])Exemplu:
Performance = IF([Total_Sales] >= 50 000, "Target Reached", "Target Not Reached")| Nume | Vânzări totale | Performanță |
|---|---|---|
| Jenny | 48.431 | Target not Reached |
| Jane | 76.528 | Target Reached |
| Dwayne | 24.167 | Target Not Reached |
| Thomas | 52.125 | Target Reached |
Toți cei trei operatori returnează TRUE sau FALSE.
AND(<logical1>,<logical2>)TRUE dacă ambele condiții sunt TRUEAND(5 < 4, 5 < 6) = AND(FALSE, TRUE) = FALSEOR(<logical1>,<logical2>)TRUE dacă cel puțin o condiție este TRUEOR(5 < 4, 5 < 6) = OR(FALSE, TRUE) = TRUENOT(<logical>)TRUE în FALSE și inversNOT(OR(5 < 4, 5 < 6)) = NOT(TRUE) = FALSEAND poate fi înlocuit cu &&
AND(5 < 4, 5 < 6) = 5 < 4 && 5 < 6 OR poate fi înlocuit cu ||
OR(5 < 4, 5 < 6) = 5 < 4 || 5 < 6Evaluează o expresie față de o listă de valori și returnează una dintre mai multe expresii de rezultat.
SWITCH(<expression>, <value>, <result>[, <value>, <result>] ... [, <else>])IF() imbricatePerformance = 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")
| Nume | Vânzări totale |
|---|---|
| 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")
| Nume | Vânzări totale | Performanță |
|---|---|---|
| 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)
| Tip îmbrăcăminte |
|---|
| Shoes |
| Pants |
| Belt |
| T-shirt |
DISCOUNT = SWITCH([Clothing Type],
"Shoes", 0.15,
"Pants", 0.20,
"Belts", 0.30,
"T-shirt", 0.25)
| Tip îmbrăcăminte | Reducere |
|---|---|
| Shoes | 15% |
| Pants | 20% |
| Belt | 30% |
| T-shirt | 25% |
DAX intermediar în Power BI