Power BI Advanced AnalyticsLesson 35 of 53
Lesson 35 of 53

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 NameTotal Sales (₹)Customer RatingIncentive Classification
Bandra West Burger2,50,0004.8Super Outlet (Bonus 15%)
Andheri East Burger2,20,0004.1 (Low Rating)Standard Outlet (Bonus 0%)
Thane Central Burger1,40,000 (Low Sales)4.9Standard 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:

Function 1

IF Function

Definition: Checks a logical condition and returns one value if TRUE, and another value if FALSE (or BLANK if omitted).

Syntax:
Order Status = IF([Total Sales] >= 100000, "High Performer", "Needs Review")
Parameters Breakdown:
  • 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.
Real-World Example (Target Achievement Flag):
Problem / Scenario: How do you flag whether monthly store target of ₹5,00,000 has been reached?
Formula: Target Reached = IF([Total Sales] >= 500000, "Achieved", "Pending")
Result: "Achieved"
Why it works: IF evaluates [Total Sales] against ₹5,00,000 and outputs the corresponding text label.
Function 2

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()`.

Syntax:
Super Delivery = IF(Fact_Orders[DeliveryMinutes] <= 15 && Fact_Orders[Rating] >= 4.5, "Star Delivery", "Standard")
Parameters Breakdown:
  • Logical1, Logical2...: Multiple conditions separated by `&&` that must all be satisfied simultaneously.
Real-World Example (Dark-Store VIP Order Criteria):
Problem / Scenario: How do you check if an order took under 12 minutes AND had basket value over ₹1,000?
Formula: Is VIP Order = IF([DeliveryMins] <= 12 && [OrderValue] >= 1000, 1, 0)
Result: 1 (Eligible)
Why it works: Both criteria must evaluate to TRUE for the formula to return 1.
Function 3

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 `||`.

Syntax:
Priority Ticket = IF(Support[Priority] = "Urgent" || Support[WaitTimeMins] > 60, "Escalate", "Normal")
Parameters Breakdown:
  • Logical1, Logical2...: Conditions separated by `||` where any single true match triggers the true branch.
Real-World Example (Customer Churn Warning Flag):
Problem / Scenario: How do you flag a customer as "At Risk" if inactive for over 90 days OR had a 1-star rating?
Formula: At Risk Flag = IF([DaysInactive] > 90 || [LastRating] = 1, "At Risk", "Safe")
Result: "At Risk"
Why it works: Meeting either threshold triggers the "At Risk" customer retention protocol.
Function 4

NOT Function

Definition: Reverses the logical value of its argument: turns TRUE into FALSE, and FALSE into TRUE.

Syntax:
Is Non Metro = NOT(Dim_Store[IsMetroCity])
Parameters Breakdown:
  • Logical: A boolean condition whose output is inverted.
Real-World Example (Inverting Eligibility Criteria):
Problem / Scenario: How do you filter customers who have NOT opted into promotional SMS alerts?
Formula: Exclude SMS = NOT(Dim_Customer[SMSOptIn])
Result: TRUE
Why it works: NOT turns the opt-in flag upside down to isolate customers requiring WhatsApp outreach instead.

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

ActionWindowsMac
Insert Logical AND symbolType "&&"Type "&&"
Insert Logical OR symbolType "||" (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.