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>])
ArgumentRequiredDescription
expressionRequiredThe value to compare. Use TRUE() to test a list of conditions instead.
valueRequiredA value (or condition) to compare with.
resultRequiredThe result when that value matches.
elseOptionalThe 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")
CountrySize
CanadaLarge
FranceMedium
GermanyMedium
MexicoSmall
United States of AmericaLarge
TotalLarge

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