Select Page

Using SWITCH function in DAX

by | Dec 5, 2020 | Video

In this video, we’ll take a look at the SWITCH function in DAX.

The SWITCH function in DAX compares a declared expression against all values. If the expression matches the value then it returns the result, if it doesn’t, it keeps moving down the list until the value is matched, or if nothing matched, then the formula returns the ELSE part.

The IF function in DAX is great when you’re using 2-3 different conditions. However, once you start having multiple conditions with several nesting Ifs, the formula becomes complicated.

In this case, I recommend using the SWITCH function, which works better with multiple IF expressions.

The SWITCH function does is it compares my declared expression against all the values you wrote down. If the expression matches the value then it returns the result. If it doesn’t, it keeps moving down the list until the value is matched, or if nothing matched, then the formula returns the ELSE part.

Below is the example of creating a calculated column of month names:

MonthName = SWITCH([Month], 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” )

Tags:

DAX | Power BI | video
Share This