SWITCH Function
Description:
The SWITCH function evaluates an expression and returns different results depending on the value of the expression.
Return Value:
SWITCH returns a scalar value coming from one of the Result expressions.
Syntax:
SWITCH( <expression>
,<value>, <result>[
, <value>, <result>]…[
, <else>]
)
- Description of the parameters:
PARAMETER |
DESCRIPTION |
---|---|
expression |
DAX expression to be evaluated, that returns a single scalar value |
value |
A constant value to be matched with the results of expression |
result |
Scalar expression to be evaluated if the results of expression match the corresponding value |
else |
If there are no matching values the else value is returned |
Example:
The following example creates a calculated column of quarter names
Quarter Name = SWITCH('Calendar'[QuarterOfYear]
,1,"Quarter 1"
,2,"Quarter 2"
,3,"Quarter 3"
,4,"Quarter 4"
,"Unknown quarter number"
)
We can use SWITCH function to replace the nested IF functions like in the example above.
Related Video: