How to Use SWITCH() in Power BI: A DAX Function Guide
Table of Contents
Introduction
DAX is a formula language that offers powerful functions for handling complex logic, and one of the most versatile among them is SWITCH() in Power BI. It simplifies multiple conditional checks into a clean and readable structure, making it ideal for categorization and scenario-based calculations.
If you’re new to DAX concepts, you may also find this blogpost helpful: Understanding the difference between VALUES(), DISTINCT(), ALL() and ALLNOBLANKROW()
In this guide, you’ll learn how to use SWITCH() to group products based on profit percentages, create custom sorting logic, and apply conditional discount rules. Whether you’re building dashboards or improving data models, mastering SWITCH() will make your Power BI reports more dynamic and insightful.
Using SWITCH()
We use SWITCH() to perform conditional calculations by evaluating an expression against multiple possible values or conditions.
You can download the Power BI file using the link provided below the blog and practice this step by step.
Let’s use SWITCH() to categorize products based on profit percentages:
- Right click on the Product table in the Fields.
- Click on New Column.
Column tools open.
- Type the following formula in the formula bar and press Enter.
In the expression above:
- The first argument in SWITCH() is TRUE(), it always returns TRUE.
- In the second argument, Product Profit % (CC) is tested, if it is greater than 0.6 than the profit group is categorized as “V.High”.
- However, if the condition in the case above is not satisfied, then the next case is tested, i.e., Product Profit % (CC) greater than 0.5. If this returns TRUE, then profit group is categorized as “High”.
- The same logic is repeated for all cases.
- If none of the condition is satisfied, the default result is “V.Low”.
Note: Since you have created a column containing text only, you will need a numerical column to sort this alphabetically.
4. Right click on the Product table in the Fields.
5. Click on New Column.
Column tools open.
6. Type the following formula in the formula bar and press Enter.
In the expression above:
- The first argument in SWITCH() is TRUE() it always returns TRUE.
- In the second argument, Product Profit % (CC) is tested, if it is greater than 0.6 than the profit group sorting order is categorized as “1”.
- However, if the condition in the case above is not satisfied then the next case is tested, i.e., Product Profit % (CC) greater than 0.5. If this returns TRUE then profit group sorting order is categorized as “2”.
- The same logic is repeated for all cases.
- If none of the condition is satisfied, the default result is “5”.
7. Click on Data tab in the left Ribbon.
8. Click on Product table in the Fields.
Now that you have created all the required columns, lets sort them.
9. Click on Profit group – Switch (CC) in the Product table.
Column tools open.
10. Click on Sort by column.
11. Click on Profit group-Sort Order (CC).
Now let’s visualize the results.
12. Click on Stacked Column chart in the Visualization Pane.
13. Drag and drop Category from the Product table to the Axis.
14. Drag and drop Product from the Product table to the Values. Rename this to “Number of Products”
15. Drag and drop Profit group – Switch (CC) from the Product table to the Legend.
16. Click on the matrix visual in the visualization pane.
17. Drag and drop Category from the Products table to the rows.
18. Drag and drop Profit group – Switch (CC) from the Product table to the Column.
19. Drag and drop Product from Product table to the Values. Right click on Product in the values section and select Count.
Switching between cases using SWITCH(): Conditional Discount Rules
We also use SWITCH() to calculate different cases.
To understand how to use SWITCH() to calculate discount:
- Right click on the Product table in the Fields.
- Click on New Column.
Column tools open.
- Type the following formula in the formula bar and press Enter.
In the expression above:
- In the first case, product colour is tested and if it is red then a value of 0.5 is assigned.
- In the second case, the existence of two conditions is evaluated simultaneously using AND() and if both are satisfied then a value of 0.40 is assigned.
- Otherwise, the value is 0.
4. Click on the “%” in the formatting section.
5. Click on the matrix visual in the visualization pane.
6. Drag and drop Category from the Products table to the rows.
7. Drag and drop New Discount % (CC) from the Product table to the Column.
8. Drag and drop Product from Product table to the Values. Right click on Product and select Count.
Conclusion
The SWITCH() function is an essential tool in Power BI for handling multiple conditions efficiently. By using SWITCH(TRUE(), …), you can replace complex nested IF statements with cleaner and more maintainable logic. As your models grow more complex, SWITCH() will become a go-to function for writing scalable and readable DAX.
FAQs
The SWITCH() function in Power BI is a DAX function that evaluates an expression against multiple conditions and returns corresponding results. It is often used as a cleaner alternative to nested IF statements.
We use SWITCH() when we have multiple conditions to evaluate. It improves readability and makes code easier to maintain compared to multiple nested IF statements.
SWITCH(TRUE(), …) is a common pattern in DAX where each condition is evaluated sequentially. The function returns the result of the first condition that evaluates to TRUE.
Extended Learning & References
For more in-depth learning and advanced Power BI training, enrol in
- Microsoft 365 Copilot Training Courses – Practical Learning for Modern Work
- Power BI Advanced Training Course.
- Power BI Report Design
- Power BI Essentials
- Power BI DAX Essentials
- Power BI Service Course







