DAX SWITCH Function

Clean, readable conditional branching without nested IF hell.

Syntax
SWITCH( Expression, Value1, Result1, [Value2, Result2, ...], [Else] )

Overview

SWITCH evaluates an expression against a series of values and returns the corresponding result. The SWITCH(TRUE(), ...) pattern enables powerful multi-condition branching.

Instead of writing 10 nested IF statements, developers use SWITCH(TRUE(), ...) to write readable case-when logic for binning customers, evaluating scorecards, and conditional KPI color indicators.

Customer Performance Tier = 
SWITCH(
    TRUE(),
    [Total Revenue] > 10000, "Platinum",
    [Total Revenue] > 5000, "Gold",
    "Silver"
)

When to use SWITCH

  • Replacing nested IF statements with a readable list of cases.
  • Choosing between measures based on a slicer selection.
  • Banding or categorising values with SWITCH(TRUE(), ...).

Worked examples

Banding with SWITCH(TRUE())

Order Size =
SWITCH (
    TRUE (),
    [Order Value] >= 10000, "Large",
    [Order Value] >= 1000, "Medium",
    "Small"
)

Conditions are checked in order and the first true one wins, so put the most restrictive condition first. The last argument is the default.

Measure selector

Selected Measure =
SWITCH (
    SELECTEDVALUE ( 'Measure Selector'[Measure] ),
    "Revenue", [Revenue],
    "Margin %", [Margin %],
    BLANK ()
)

Returning BLANK() as the default keeps visuals empty rather than showing a misleading number when nothing (or several items) is selected.

Common mistakes

  • Ordering conditions incorrectly: in SWITCH(TRUE(), ...), DAX evaluates top-to-bottom and stops at the first TRUE condition.
  • Returning inconsistent data types in different branch results.

Performance notes

SWITCH is usually efficient, but in some query shapes the engine evaluates more branches than you expect, especially when SWITCH is used inside an iterator over a large table. If a SWITCH-based measure is slow, test each branch separately and move the SWITCH outside the iterator where possible.

Frequently asked questions

SWITCH vs nested IF — which is faster?
They usually perform similarly; SWITCH is preferred for readability. The performance difference comes from the branches' expressions, not from the choice of SWITCH or IF.
Can SWITCH return a table?
No. SWITCH returns a scalar value. To switch between tables, restructure the logic, for example with separate measures.
Why does my SWITCH(TRUE()) return the wrong band?
The first true condition wins. If a broader condition (>= 1000) comes before a narrower one (>= 10000), large values match the broader band first. Order conditions from most to least restrictive.

Related DAX concepts