Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Switch formula with blank and multiple conditions

Hello,

 

I have a formula I am trying to clean up and it has me stumped. The original formula is:

 

Reason Codes =

IF('Version'[This vs That] = "That",
IF('Version'[Reason]= "0","No Exception",
IF('Version'[Reason]= BLANK(),"No Exception",
IF('Version'[Reason]="1","Error",
IF('Version'[Reason] = "2","Good",
IF('Version'[Reason]= "3","Other",


)))))

 

I have created the following switch formula:

 

Reason Code = 
 
SWITCH (
 
TRUE (),
'Version'[Reason] IN { 0 }, "No Exception",
'Version'[Reason] IN { 1, 01 }, "Error",
'Version'[Reason] IN { 2, 02 }, "Good",
'Version'[Reason] IN { 3, 03 }, "Other",
)
But I'm hitting walls on adding in blanks & taking that first If formula into the equation.
 
Table example:
Knoble_0-1723237819554.png

 

Thank you in advance!

 
1 ACCEPTED SOLUTION

Like this? (Change the order as needed.)

Reason Code =
SWITCH (
    TRUE (),
    ISBLANK ( 'Version'[Reason] ), "No Exception",
    'Version'[This vs That] <> "That", BLANK (),
    'Version'[Reason] IN { 0 }, "No Exception",
    'Version'[Reason] IN { 1, 75 }, "Error",
    'Version'[Reason] IN { 2, 51 }, "Good",
    'Version'[Reason] IN { 3, 100 }, "Other"
)

 

View solution in original post

6 REPLIES 6
AlexisOlson
Super User
Super User

You can do it in one big SWITCH

Reason Codes = 
SWITCH (
    TRUE(),
    'Version'[This vs That] = "That" && 'Version'[Reason] = "0", "No Exception",
    'Version'[This vs That] = "That" && 'Version'[Reason] = BLANK(), "No Exception",
    'Version'[This vs That] = "That" && 'Version'[Reason] = "1", "Error",
    'Version'[This vs That] = "That" && 'Version'[Reason] = "2", "Good",
    'Version'[This vs That] = "That" && 'Version'[Reason] = "3", "Other"
)

 

Or only apply the switch to the Reason part:

Reason Codes =
IF (
    Version[This vs That] = "That",
    SWITCH (
        Version[Reason],
        BLANK (), "No Exception",
        "0", "No Exception",
        "1", "Error",
        "2", "Good",
        "3", "Other"
    )
)
Anonymous
Not applicable

OK, but as the data set gets larger, it will be become just as large as the old dax formula. I was hoping to have something to tighten up the code. 

Ex:

 

Reason Code = 
 
SWITCH (
 
TRUE (),
'Version'[Reason] IN { 0 }, "No Exception",
'Version'[Reason] IN { 1, 75 }, "Error",
'Version'[Reason] IN { 2, 51 }, "Good",
'Version'[Reason] IN { 3, 100 }, "Other",
)

 

Knoble_1-1723240063752.png

 

 

Using IN works fine. How about this?

 

Reason Code =
SWITCH (
    TRUE (),
    'Version'[This vs That] <> "That", BLANK (),
    'Version'[Reason] IN { 0 }, "No Exception",
    'Version'[Reason] IN { 1, 75 }, "Error",
    'Version'[Reason] IN { 2, 51 }, "Good",
    'Version'[Reason] IN { 3, 100 }, "Other"
)
Anonymous
Not applicable

Is there a way to make blank a no exception because as shown in the example (and the larger actual dataset) there are quite a few blanks (infuriating but here we are)?

Like this? (Change the order as needed.)

Reason Code =
SWITCH (
    TRUE (),
    ISBLANK ( 'Version'[Reason] ), "No Exception",
    'Version'[This vs That] <> "That", BLANK (),
    'Version'[Reason] IN { 0 }, "No Exception",
    'Version'[Reason] IN { 1, 75 }, "Error",
    'Version'[Reason] IN { 2, 51 }, "Good",
    'Version'[Reason] IN { 3, 100 }, "Other"
)

 

Anonymous
Not applicable

Works great! Thank you!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors