Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
I've read that Switch statements are more efficient and less costly than IF statements so I'm trying to convert this code to Switch
but I'm not sure how I can avoid the IF at the beginning?
Days to Validation Bins =
IF(AND('Cases'[Created On] < DATEVALUE("01/04/2020"), 'Cases'[statecode] = "Resolved" || "2"),BLANK(),
IF(ISBLANK('Cases'[Days to Validation]),BLANK(),
IF( 'Cases'[Days to Validation] <= 30 , "0-1 Mth",
IF('Cases'[Days to Validation] <= 60, "1-2 Mths",
IF('Cases'[Days to Validation] <= 90, "2-3 Mths",
"Older")
))))
Solved! Go to Solution.
Days to Validation Bins = //Try this
VAR _Created = 'Cases'[Created On]
VAR _State = 'Cases'[statecode]
VAR _Days = 'Cases'[Days to Validation]
RETURN
SWITCH(
TRUE(),
AND(_Created < DATE(2020,4,1), OR(_State = "Resolved", _State = "2")), BLANK(),
ISBLANK(_Days), BLANK(),
_Days <= 30, "0-1 Mth",
_Days <= 60, "1-2 Mths",
_Days <= 90, "2-3 Mths",
"Older"
)
Did I answer your question? If so, please mark my post as a solution!
Proud to be a Super User!
Hi @ArchStanton
One thing's for sure: SWITCH is less verbose and easier to read
Days to Validation Bins =
SWITCH(
TRUE(),
ISBLANK('Cases'[Days to Validation]) ||
(
'Cases'[Created On] < DATE(2020, 4, 1) &&
'Cases'[statecode] IN {"Resolved", "2"}
), BLANK(),
'Cases'[Days to Validation] <= 30, "0-1 Mth",
'Cases'[Days to Validation] <= 60, "1-2 Mths",
'Cases'[Days to Validation] <= 90, "2-3 Mths",
"Older"
)
Thanks for this!
Days to Validation Bins = //Try this
VAR _Created = 'Cases'[Created On]
VAR _State = 'Cases'[statecode]
VAR _Days = 'Cases'[Days to Validation]
RETURN
SWITCH(
TRUE(),
AND(_Created < DATE(2020,4,1), OR(_State = "Resolved", _State = "2")), BLANK(),
ISBLANK(_Days), BLANK(),
_Days <= 30, "0-1 Mth",
_Days <= 60, "1-2 Mths",
_Days <= 90, "2-3 Mths",
"Older"
)
Did I answer your question? If so, please mark my post as a solution!
Proud to be a Super User!
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 37 | |
| 37 | |
| 33 | |
| 32 | |
| 29 |
| User | Count |
|---|---|
| 130 | |
| 88 | |
| 82 | |
| 68 | |
| 64 |