Skip to main content

SWITCH DAX Function

Evaluates an expression against a list of values and returns one of multiple possible result expressions. It’s comes under Logical Dax function category.

Syntax:

SWITCH(<expression>, <value>, <result>[, <value>, <result>]…[, <else>])

Description:

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.

Note:

All result expressions and the else expression must be of the same data type.

So, Let’s start with an example,  you can download the sample Dataset from below link
Step 1: Create one measure and write conditional statement as mentioned below.
 
Sales_Tag =
Var TotalSales= SUM(Orders[Sales])
Return
SWITCH(TRUE(),
TotalSales<50000, "Low",
TotalSales>50000 && TotalSales< 100000, "Medium",
TotalSales>100000, "High",
"Other"
)
 
Step 2: If condition has true, Switch will return the result in form of “Low”, “Medium” & “High”.


Step-3: You can change the font color white for Sales_Tag measure total, because here no need to display Text as in Total. Due to this.
Select table visual >  format bar > field Formatting, and follow the below properties:
  • Select Sales_Tag from dropdown
  • Choose font color white, by default it is selected but select again to apply this.
  • Turned off Apply to values
  • Turned on Apply to total

Get Month Name from Month number:

Create one calculated column, and write below SWICTH DAX formula to get month name from month number.

Return Month Name =

SWITCH(Orders[MonthNumber],

1,"January",

2,"February",

3,"March",

4,"April",

5,"May",

6,"June",

7,"July",

8,"August",

9,"September",

10,"October",

11,"November",

12,"December",

"Invalid Month Number"

)



Hope you enjoyed the post. Your valuable feedback, question, or comments about this post are always welcome

Comments

Popular posts from this blog

ALL DAX function

As it’s name suggests, Returns all the rows in a table, or all the values in a column.  ALL function removes the applied filters from the filter context. Its comes under Filter function DAX category.

LOOKUPVALUE DAX Function

Returns the value for the row that meets all criteria specified by search conditions. The function can apply one or more search conditions. Its comes under Filter function DAX category.