DAX and data models
How to Write Multiple IF Statements in Power BI With SWITCH
Replace nested IF statements in Power BI with SWITCH ( TRUE (), ... ). Syntax, working DAX examples, AND and OR conditions, and the mistakes that break it.
Sajagan Thirugnanam
·
Updated
To write multiple IF statements in Power BI, use SWITCH ( TRUE (), condition1, result1, condition2, result2, ..., else ) instead of nesting one IF inside another. A Power BI nested IF works, but every extra condition adds another level of brackets, and SWITCH keeps all the conditions in one flat list. This post shows both, with working DAX for each, and the mistakes that make a SWITCH return the wrong answer.
Power BI multiple IF statements: the nested IF way
The DAX IF function checks one condition:
IF ( <logical_test>, <value_if_true> [, <value_if_false>To check a second condition, you put another IF in the value_if_false slot. That is a nested IF. Say you want to group products by sales price:
Under 500 is Low.
500 to 999 is Medium.
1,000 and above is High.
As a calculated column on the Product table, the nested IF version is:
Price Category =
IF (
'Product'[Sales Price] < 500,
"Low",
IF (
'Product'[Sales Price] < 1000,
"Medium",
"High"
)
)With three outcomes this is still readable. With six or seven, the brackets pile up at the end and it gets hard to see which result belongs to which test. Adding a new band means finding the right level to insert it.
How the SWITCH function works
SWITCH evaluates one expression and compares the result with a list of values. It returns the result paired with the first value that matches.
SWITCH ( <expression>, <value>, <result> [, <value>, <result>] ... [, <else>Argument | What it does |
|---|---|
| Any DAX expression that returns a single value. It is evaluated once for each row or filter context. |
| A constant to compare with the result of |
| What to return when |
| Optional. What to return when no value matches. Without it, |
There are two ways to use it. You can match a column against fixed values, or you can pass TRUE () as the expression and write a condition in each value slot.
Matching exact values with SWITCH
When each case is an exact value, put the column itself in the expression slot. This example turns a region code into its full name:
Region Name =
SWITCH (
Sales[Region],
"EMEA", "Europe, Middle East and Africa",
"APJ", "Asia Pacific and Japan",
"AMER", "Americas",
"LATAM", "Latin America",
"Unknown region"
)Any code that is not in the list, including a blank, returns "Unknown region". Always add an else value. Without it, a code you forgot returns blank and the row quietly drops out of any grouping by region name.
A common use of this pattern is turning month abbreviations into full month names. You do not need a twelve-branch SWITCH for that. If your table has a real date column, FORMAT ( 'Calendar'[Date], "mmmm" ) returns the full month name directly. A hand-written list is also easy to get wrong: it is easy to skip a month by accident.
DAX multiple IF statements with SWITCH ( TRUE () )
For ranges and comparisons, pass TRUE () as the expression. Each value slot then holds a condition. SWITCH returns the result for the first condition that is true.
Here is the price category again:
Price Category =
SWITCH (
TRUE (),
'Product'[Sales Price] < 500, "Low",
'Product'[Sales Price] < 1000, "Medium",
"High"
)This returns the same results as the nested IF above. The first condition catches everything under 500. The second only sees prices of 500 or more, so < 1000 means 500 to 999. Anything left is 1,000 or more and gets the else value, "High".
Leaving out TRUE () is the most common SWITCH mistake. Without it, DAX treats the first condition as the expression and "Low" as the value to compare it with. A true/false result never equals the text "Low", so no branch matches.
Power BI IF statement with multiple conditions
Sometimes one branch needs two tests at once. DAX gives you three ways to combine conditions:
&&means AND. Both sides must be true.||means OR. At least one side must be true.AND ( a, b )andOR ( a, b )do the same, but take exactly two arguments. For three or more conditions, chain&&or||.
These work inside IF and inside each SWITCH branch:
Order Priority =
SWITCH (
TRUE (),
Sales[Amount] >= 10000 && Sales[Channel] = "Online", "Priority online",
Sales[Amount] >= 10000, "Priority",
Sales[Region] = "EMEA" || Sales[Region] = "APJ", "International",
"Standard"
)To test one column against a list, IN is shorter than a chain of ||:
Is International =
IF ( Sales[Region] IN { "EMEA", "APJ" }, "Yes", "No" )Evaluating ranges with a measure
SWITCH also works in measures. This measure puts the ROI of the current selection into a band. It assumes an existing [ROI] measure that returns a ratio, where 0.6 means 60%.
ROI Range =
VAR CurrentROI = [ROI]
RETURN
SWITCH (
TRUE (),
ISBLANK ( CurrentROI ), BLANK (),
CurrentROI < 0, "Negative",
CurrentROI <= 0.6, "0% to 60%",
CurrentROI <= 0.7, "60% to 70%",
CurrentROI <= 0.8, "70% to 80%",
CurrentROI <= 0.9, "80% to 90%",
CurrentROI <= 1.0, "90% to 100%",
"Over 100%"
)Because conditions are checked in order, each one only needs an upper bound. The variable stores the ROI once, so the measure is not evaluated again for each branch. Our guide to DAX variables covers this in more detail.
The first branch returns blank when there is no ROI, so empty rows stay empty instead of being labeled.
Mistakes that break SWITCH
Four things cause most wrong SWITCH results:
Missing TRUE (). Conditions in the value slots only work when the expression is
TRUE ().Wrong order. The first true condition wins. If you write
< 1000before< 500, every price under 1,000 is Medium and nothing is ever Low. Put the narrowest condition first.Mixed data types. Every result and the else value must have the same data type. Returning text in one branch and a number in another gives an error.
Gaps in the ranges. A value that matches no branch gets the else value, or blank if there is none. Test the edges, such as exactly 500 or a negative number, before you publish.
Calculated column or measure
The price category depends only on values in the same row, so it can be a calculated column. The ROI band depends on what the reader has selected, so it must be a measure. Our post on measures vs calculated columns explains how to choose. For why the same formula behaves differently in each, see row context vs filter context.
IF and SWITCH often sit inside a CALCULATE or another measure. Our complete DAX guide and the post on the CALCULATE function cover those building blocks.
FAQs
What is the difference between Switch and If in Power BI?
IF checks one condition and returns one of two results. To handle more outcomes, you nest another IF inside it. SWITCH takes a list of value and result pairs in one function, plus an optional else value. With SWITCH ( TRUE (), ... ), each pair can be a full condition. The result is the same as a nested IF, but the conditions sit in one flat list that is easier to read and change.
Is it better to use If or Switch?
Use IF for one or two conditions, such as a yes/no flag. Use SWITCH when there are three or more outcomes, or when you expect to add more later. Choose SWITCH for readability, not for speed. It evaluates the conditions in order, just as a nested IF does.
Sources
SWITCH function (DAX) - Microsoft Learn
IF function (DAX) - Microsoft Learn
DAX operators - Microsoft Learn
To write multiple IF statements in Power BI, use SWITCH ( TRUE (), condition1, result1, condition2, result2, ..., else ) instead of nesting one IF inside another. A Power BI nested IF works, but every extra condition adds another level of brackets, and SWITCH keeps all the conditions in one flat list. This post shows both, with working DAX for each, and the mistakes that make a SWITCH return the wrong answer.
Power BI multiple IF statements: the nested IF way
The DAX IF function checks one condition:
IF ( <logical_test>, <value_if_true> [, <value_if_false>To check a second condition, you put another IF in the value_if_false slot. That is a nested IF. Say you want to group products by sales price:
Under 500 is Low.
500 to 999 is Medium.
1,000 and above is High.
As a calculated column on the Product table, the nested IF version is:
Price Category =
IF (
'Product'[Sales Price] < 500,
"Low",
IF (
'Product'[Sales Price] < 1000,
"Medium",
"High"
)
)With three outcomes this is still readable. With six or seven, the brackets pile up at the end and it gets hard to see which result belongs to which test. Adding a new band means finding the right level to insert it.
How the SWITCH function works
SWITCH evaluates one expression and compares the result with a list of values. It returns the result paired with the first value that matches.
SWITCH ( <expression>, <value>, <result> [, <value>, <result>] ... [, <else>Argument | What it does |
|---|---|
| Any DAX expression that returns a single value. It is evaluated once for each row or filter context. |
| A constant to compare with the result of |
| What to return when |
| Optional. What to return when no value matches. Without it, |
There are two ways to use it. You can match a column against fixed values, or you can pass TRUE () as the expression and write a condition in each value slot.
Matching exact values with SWITCH
When each case is an exact value, put the column itself in the expression slot. This example turns a region code into its full name:
Region Name =
SWITCH (
Sales[Region],
"EMEA", "Europe, Middle East and Africa",
"APJ", "Asia Pacific and Japan",
"AMER", "Americas",
"LATAM", "Latin America",
"Unknown region"
)Any code that is not in the list, including a blank, returns "Unknown region". Always add an else value. Without it, a code you forgot returns blank and the row quietly drops out of any grouping by region name.
A common use of this pattern is turning month abbreviations into full month names. You do not need a twelve-branch SWITCH for that. If your table has a real date column, FORMAT ( 'Calendar'[Date], "mmmm" ) returns the full month name directly. A hand-written list is also easy to get wrong: it is easy to skip a month by accident.
DAX multiple IF statements with SWITCH ( TRUE () )
For ranges and comparisons, pass TRUE () as the expression. Each value slot then holds a condition. SWITCH returns the result for the first condition that is true.
Here is the price category again:
Price Category =
SWITCH (
TRUE (),
'Product'[Sales Price] < 500, "Low",
'Product'[Sales Price] < 1000, "Medium",
"High"
)This returns the same results as the nested IF above. The first condition catches everything under 500. The second only sees prices of 500 or more, so < 1000 means 500 to 999. Anything left is 1,000 or more and gets the else value, "High".
Leaving out TRUE () is the most common SWITCH mistake. Without it, DAX treats the first condition as the expression and "Low" as the value to compare it with. A true/false result never equals the text "Low", so no branch matches.
Power BI IF statement with multiple conditions
Sometimes one branch needs two tests at once. DAX gives you three ways to combine conditions:
&&means AND. Both sides must be true.||means OR. At least one side must be true.AND ( a, b )andOR ( a, b )do the same, but take exactly two arguments. For three or more conditions, chain&&or||.
These work inside IF and inside each SWITCH branch:
Order Priority =
SWITCH (
TRUE (),
Sales[Amount] >= 10000 && Sales[Channel] = "Online", "Priority online",
Sales[Amount] >= 10000, "Priority",
Sales[Region] = "EMEA" || Sales[Region] = "APJ", "International",
"Standard"
)To test one column against a list, IN is shorter than a chain of ||:
Is International =
IF ( Sales[Region] IN { "EMEA", "APJ" }, "Yes", "No" )Evaluating ranges with a measure
SWITCH also works in measures. This measure puts the ROI of the current selection into a band. It assumes an existing [ROI] measure that returns a ratio, where 0.6 means 60%.
ROI Range =
VAR CurrentROI = [ROI]
RETURN
SWITCH (
TRUE (),
ISBLANK ( CurrentROI ), BLANK (),
CurrentROI < 0, "Negative",
CurrentROI <= 0.6, "0% to 60%",
CurrentROI <= 0.7, "60% to 70%",
CurrentROI <= 0.8, "70% to 80%",
CurrentROI <= 0.9, "80% to 90%",
CurrentROI <= 1.0, "90% to 100%",
"Over 100%"
)Because conditions are checked in order, each one only needs an upper bound. The variable stores the ROI once, so the measure is not evaluated again for each branch. Our guide to DAX variables covers this in more detail.
The first branch returns blank when there is no ROI, so empty rows stay empty instead of being labeled.
Mistakes that break SWITCH
Four things cause most wrong SWITCH results:
Missing TRUE (). Conditions in the value slots only work when the expression is
TRUE ().Wrong order. The first true condition wins. If you write
< 1000before< 500, every price under 1,000 is Medium and nothing is ever Low. Put the narrowest condition first.Mixed data types. Every result and the else value must have the same data type. Returning text in one branch and a number in another gives an error.
Gaps in the ranges. A value that matches no branch gets the else value, or blank if there is none. Test the edges, such as exactly 500 or a negative number, before you publish.
Calculated column or measure
The price category depends only on values in the same row, so it can be a calculated column. The ROI band depends on what the reader has selected, so it must be a measure. Our post on measures vs calculated columns explains how to choose. For why the same formula behaves differently in each, see row context vs filter context.
IF and SWITCH often sit inside a CALCULATE or another measure. Our complete DAX guide and the post on the CALCULATE function cover those building blocks.
FAQs
What is the difference between Switch and If in Power BI?
IF checks one condition and returns one of two results. To handle more outcomes, you nest another IF inside it. SWITCH takes a list of value and result pairs in one function, plus an optional else value. With SWITCH ( TRUE (), ... ), each pair can be a full condition. The result is the same as a nested IF, but the conditions sit in one flat list that is easier to read and change.
Is it better to use If or Switch?
Use IF for one or two conditions, such as a yes/no flag. Use SWITCH when there are three or more outcomes, or when you expect to add more later. Choose SWITCH for readability, not for speed. It evaluates the conditions in order, just as a nested IF does.
Sources
SWITCH function (DAX) - Microsoft Learn
IF function (DAX) - Microsoft Learn
DAX operators - Microsoft Learn
Show us your report nobody trusts.
1 · A 30-minute call.
2 · We look at your current reports together.
3 · We tell you what we would do.
Show us your report nobody trusts.
1 · A 30-minute call.
2 · We look at your current reports together.
3 · We tell you what we would do.
Show us your report nobody trusts.
1 · A 30-minute call.
2 · We look at your current reports together.
3 · We tell you what we would do.
CaseWhen is a Berlin BI consultancy that builds reporting that leaders can trust, on the Microsoft stack: Power BI, Fabric and Azure.
Berlin, Germany
Free tools
CaseWhen is a Berlin BI consultancy that builds reporting that leaders can trust, on the Microsoft stack: Power BI, Fabric and Azure.
Berlin, Germany
Free tools
CaseWhen is a Berlin BI consultancy that builds reporting that leaders can trust, on the Microsoft stack: Power BI, Fabric and Azure.
Berlin, Germany
