DAX Logical Functions
Logical functions evaluate conditions and return results based on whether conditions are true or false. They are essential for implementing business logic in Power BI.
IF()
Evaluates a condition and returns one value if true, another if false.
Syntax: IF(Condition, ValueIfTrue, ValueIfFalse)
Examples:
Status = IF(Sales[Amount] > 1000, "High", "Low")
Profit Status = IF([Total Profit] > 0, "Profit", "Loss")
Nested IF:
Grade =
IF(Sales[Score] >= 90, "A",
IF(Sales[Score] >= 80, "B",
IF(Sales[Score] >= 70, "C", "D")))
Tip: For multiple conditions, prefer SWITCH() over nested IF() for readability.
SWITCH()
Evaluates an expression against a list of values and returns the corresponding result. Cleaner alternative to nested IF statements.
Syntax: SWITCH(Expression, Value1, Result1, Value2, Result2, ..., DefaultResult)
Examples:
Day Name =
SWITCH(
Dates[DayNumber],
1, "Monday",
2, "Tuesday",
3, "Wednesday",
4, "Thursday",
5, "Friday",
6, "Saturday",
7, "Sunday",
"Unknown"
)
SWITCH with TRUE() — for conditions:
Sales Category =
SWITCH(
TRUE(),
[Total Sales] > 100000, "Platinum",
[Total Sales] > 50000, "Gold",
[Total Sales] > 10000, "Silver",
"Bronze"
)
AND() and OR()
| Function | Description | Returns TRUE when |
|---|---|---|
AND() | Logical AND | Both conditions are true |
OR() | Logical OR | At least one condition is true |
NOT() | Logical NOT | The condition is false |
Syntax: AND(Condition1, Condition2) OR(Condition1, Condition2)
Using Operators (Alternative Syntax):
Eligible = IF(Sales[Age] >= 18 && Sales[Status] = "Active", "Yes", "No")
• && is equivalent to AND() • || is equivalent to OR()
Examples:
VIP Customer =
IF(
AND(Customers[TotalSpend] > 50000, Customers[Years] > 3),
"VIP",
"Regular"
)
Needs Attention =
IF(
OR([Sales] < 1000, [Returns] > 100),
"Review",
"OK"
)
Comparison: IF vs SWITCH
| Feature | IF() | SWITCH() |
|---|---|---|
| Best For | Simple true/false conditions | Multiple discrete values |
| Readability | Gets messy with nesting | Clean with many options |
| Performance | Slightly faster for 1-2 conditions | Better for 3+ conditions |
| Flexibility | Can use any expression | Matches exact values (or TRUE() pattern) |