Case Statement in Power BI
Case Statement in Power BI, A case statement is a type of statement that evaluates conditions and returns a value when the first condition is met.
In Power BI, the easiest way to implement a case statement is by using the SWITCH function in DAX.
Basic Syntax of SWITCH Function
The basic syntax of the SWITCH function is as follows:
new = SWITCH(
'my_data'[Position],
"G", "Guard",
"F", "Forward",
"C", "Center",
"None"
)Case Statement in Power BI
In this example, a new column named new is created. It examines the values in the Position column of the my_data table and returns:
- “Guard” if
Positionequals “G” - “Forward” if
Positionequals “F” - “Center” if
Positionequals “C” - “None” if
Positioncontains any other value
Practical Example: Using SWITCH in Power BI
Let’s walk through a practical example to see how this function works in Power BI.
Suppose we have a table named my_data in Power BI that contains information about various basketball players. We want to create a new column that converts the values in the Position column from “C”, “G”, and “F” to “Center”, “Guard”, and “Forward” respectively.
- Open Power BI Desktop and navigate to the
Table toolstab. - Click the
New columnicon. - Enter the following formula into the formula bar:
new = SWITCH(
'my_data'[Position],
"G", "Guard",
"F", "Forward",
"C", "Center",
"None"
)This formula will generate a new column called new containing the values specified in the SWITCH function.
Result of the SWITCH Function
The new column will display the following values:
- “Guard” if
Positionis “G” - “Forward” if
Positionis “F” - “Center” if
Positionis “C” - “None” if
Positionis any other value
By following these steps, you can efficiently create a case statement in Power BI using the SWITCH function.
This method not only simplifies the process but also enhances the readability and manageability of your data transformation logic.
Enhance Your Power BI Skills
By mastering the SWITCH function and case statements in Power BI, you can streamline your data analysis and reporting tasks.
Continue exploring more Power BI features to become proficient in creating insightful and actionable reports.

