DAX SWITCH function
Compares a value against a list and returns the result of the first match.
SWITCH replaces long chains of IFs. With TRUE() as the first argument, it checks a list of conditions in order and returns the first one that is true.
Syntax
SWITCH(<expression>, <value>, <result>[, <value>, <result>]…[, <else>])| Argument | Required | Description |
|---|---|---|
| expression | Required | The value to compare. Use TRUE() to test a list of conditions instead. |
| value | Required | A value (or condition) to compare with. |
| result | Required | The result when that value matches. |
| else | Optional | The result when nothing matches. Blank if left out. |
Returns: The result of the first match, or the else value.
Examples
Calculated on the free practice data (table financials), with [Total Sales] = SUM(financials[Sales]) and [Total Profit] = SUM(financials[Profit]).
1. Size band by country
Size = SWITCH(TRUE(), [Total Sales] > 24500000, "Large", [Total Sales] > 22000000, "Medium", "Small")| Country | Size |
|---|---|
| Canada | Large |
| France | Medium |
| Germany | Medium |
| Mexico | Small |
| United States of America | Large |
| Total | Large |
Conditions are checked from top to bottom; the first true one wins, so put the strictest first.
Good to know
- The order of the conditions matters with SWITCH(TRUE(), …).
- Always give an else result, so unexpected values don't silently become blank.
Related functions
Official reference: SWITCH function on Microsoft Learn