SWITCH DAX Function in Power BI
The SWITCH DAX function evaluates an expression against a list of values and returns one of multiple possible result expressions.
DAX Syntax SWITCH(Expression, Value1, Result1[, Value2, Result2]…[,Else])
The function has the following parameters:
- Expression: Any DAX expression that returns a single scalar value, where the expression is to be evaluated multiple times (for each row/context).
- Value: A constant value to be matched with the results of Expression.
- Result: Any scalar expression to be evaluated if the results of Expression match the corresponding Value.
- Else: Any scalar expression to be evaluated if the result of Expression doesn't match any of the Value arguments.
Example: The following example creates a calculated column of month names.
DAX
Month name =
SWITCH(
MONTH(Sheet1[Dates]),
1, "January",
2, "February",
3, "March",
4, "April",
5, "May",
6, "June",
7, "July",
8, "August",
9, "September",
10, "October",
11, "November",
12, "December",
"Unknown month number"
) The output of the above code is shown below:
