Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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:
Thank you in advance!
Solved! Go to 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"
)
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"
)
)
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:
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"
)
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"
)
Works great! Thank you!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
84 | |
76 | |
73 | |
42 | |
36 |
User | Count |
---|---|
109 | |
56 | |
52 | |
48 | |
42 |