Multi-Condition Switching: SWITCH(TRUE(), ...) Pattern
Overview & Learning Objectives
Business rules are fundamentally conditional: "If sales exceed target, grant a 10% bonus; otherwise, grant 0%." DAX provides familiar logical functions: `IF()`, `AND()` (or `&&`), `OR()` (or `||`), and `NOT()`. Mastering conditional branching allows you to classify data, assign dynamic targets, and control measure outputs seamlessly.
- Master the syntax of `IF(LogicalTest, ResultIfTrue, [ResultIfFalse])`.
- Use logical operators `&&` (AND) and `||` (OR) to combine multiple conditions cleanly.
- Understand the limitations of deeply nested IF statements and when to switch to `SWITCH()`.
Industry Standard
Standard: Enterprise DAX guidelines at Microsoft and Accenture recommend using native operator symbols (`&&` and `||`) instead of nested `AND()` and `OR()` functions for superior code legibility.
Real-World Example: Burger Point Incentive Engine
Burger Point awards a "Super Outlet" badge to outlets that achieve more than ₹ 2,00,000 in sales AND maintain customer ratings >= 4.5.
| Outlet Name | Total Sales (₹) | Customer Rating | Incentive Classification |
|---|---|---|---|
| Bandra West Burger | 2,50,000 | 4.8 | Super Outlet (Bonus 15%) |
| Andheri East Burger | 2,20,000 | 4.1 (Low Rating) | Standard Outlet (Bonus 0%) |
| Thane Central Burger | 1,40,000 (Low Sales) | 4.9 | Standard Outlet (Bonus 0%) |
Functions Covered in this Chapter
Here is the definition, exact syntax, parameter breakdown, and real-world business example for each function covered in this chapter:
IF Function
Definition: Checks a logical condition and returns one value if TRUE, and another value if FALSE (or BLANK if omitted).
Order Status = IF([Total Sales] >= 100000, "High Performer", "Needs Review")
LogicalTest: Any expression that resolves to TRUE or FALSE.ResultIfTrue: Value returned when the condition evaluates to TRUE.ResultIfFalse: Optional fallback value returned when condition evaluates to FALSE.
Target Reached = IF([Total Sales] >= 500000, "Achieved", "Pending")AND Function / Operator (&&)
Definition: Returns TRUE if all conditions are true; returns FALSE if any condition is false. In DAX, `&&` is preferred over nested `AND()`.
Super Delivery = IF(Fact_Orders[DeliveryMinutes] <= 15 && Fact_Orders[Rating] >= 4.5, "Star Delivery", "Standard")
Logical1, Logical2...: Multiple conditions separated by `&&` that must all be satisfied simultaneously.
Is VIP Order = IF([DeliveryMins] <= 12 && [OrderValue] >= 1000, 1, 0)OR Function / Operator (||)
Definition: Returns TRUE if at least one of the conditions is true; returns FALSE only when all conditions are false. DAX uses `||`.
Priority Ticket = IF(Support[Priority] = "Urgent" || Support[WaitTimeMins] > 60, "Escalate", "Normal")
Logical1, Logical2...: Conditions separated by `||` where any single true match triggers the true branch.
At Risk Flag = IF([DaysInactive] > 90 || [LastRating] = 1, "At Risk", "Safe")NOT Function
Definition: Reverses the logical value of its argument: turns TRUE into FALSE, and FALSE into TRUE.
Is Non Metro = NOT(Dim_Store[IsMetroCity])
Logical: A boolean condition whose output is inverted.
Exclude SMS = NOT(Dim_Customer[SMSOptIn])Common Mistakes & Limitations
- Writing deeply nested IF statements 5 levels deep (e.g. `IF(a, 1, IF(b, 2, IF(c, 3, ...)))`); this is unmaintainable and should be written with `SWITCH()`.
- Returning mixed data types from IF (e.g. returning the number `100` if true and text `"None"` if false), which forces the measure to evaluate as Text.
Keyboard Shortcuts
| Action | Windows | Mac |
|---|---|---|
| Insert Logical AND symbol | Type "&&" | Type "&&" |
| Insert Logical OR symbol | Type "||" (Shift + Backslash) | Type "||" |
Pro Tips & Modern Alternatives
- Use `COALESCE(val1, val2)` as a fast shortcut for `IF(ISBLANK(val1), val2, val1)`.
- Always transition to `SWITCH(TRUE(), ...)` when evaluating more than two conditional branches.