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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Agustina
Frequent Visitor

Why SWITCH does not work as expected replace for my nested IFs?

 Hello colleagues,

 

I am working creating a calculated column to get different due dates based on each item priority and status.

I used to have nested IFs and worked perfectly fine, but I would like to be more efficient and use SWITCH instead, although I cannot get it to fully work - most of the rows I get are blanks.

 

Here are both exppressions:

 

DueDate_OldButWorking =
IF(
NOT(ISBLANK('2021 Cases'[Submission Date])) && RELATED(AUX_DetailedStatus[Level]) > 4,
IF(
RELATED(AUX_Priority[Level]) = 3,
'2021 Cases'[Submission Date] + 21,
IF(
RELATED(AUX_Priority[Level]) = 1 || RELATED(AUX_DetailedStatus[Level]) = 2,
'2021 Cases'[Submission Date] + 5,
BLANK()
)
)
)
 
DueDate_New =
SWITCH(
TRUE(),
NOT(ISBLANK('2021 Cases'[Submission Date])) && RELATED(AUX_DetailedStatus[Level]) > 4 && RELATED(AUX_Priority[Level]) = 3, DATEADD('2021 Cases'[Submission Date], 21, DAY),
NOT(ISBLANK('2021 Cases'[Submission Date])) && RELATED(AUX_DetailedStatus[Level]) > 4 && RELATED(AUX_Priority[Level]) = 2, DATEADD('2021 Cases'[Submission Date], 5,DAY),
NOT(ISBLANK('2021 Cases'[Submission Date])) && RELATED(AUX_DetailedStatus[Level]) > 4 && RELATED(AUX_Priority[Level]) = 1, DATEADD('2021 Cases'[Submission Date], 5,DAY),
BLANK()
)
 
Can you identify what is that I am not doing correctly?
Many thanks in advance!
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Agustina , Try like

 

DueDate_New =
if(NOT(ISBLANK('2021 Cases'[Submission Date])) ,
SWITCH(
TRUE(),
RELATED(AUX_DetailedStatus[Level]) > 4 && RELATED(AUX_Priority[Level]) = 3, DATEADD('2021 Cases'[Submission Date], 21, DAY),
RELATED(AUX_DetailedStatus[Level]) > 4 && RELATED(AUX_Priority[Level]) in {1,2}, DATEADD('2021 Cases'[Submission Date], 5,DAY),
BLANK()
), blank())

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

@Agustina 

 

Just a quickie: The fact that you get 2 different results from IF and SWITCH only mean that your SWITCH is NOT logically equivalent to your IF. You just make a logical mistake when you translate into SWITCH.

amitchandak
Super User
Super User

@Agustina , Try like

 

DueDate_New =
if(NOT(ISBLANK('2021 Cases'[Submission Date])) ,
SWITCH(
TRUE(),
RELATED(AUX_DetailedStatus[Level]) > 4 && RELATED(AUX_Priority[Level]) = 3, DATEADD('2021 Cases'[Submission Date], 21, DAY),
RELATED(AUX_DetailedStatus[Level]) > 4 && RELATED(AUX_Priority[Level]) in {1,2}, DATEADD('2021 Cases'[Submission Date], 5,DAY),
BLANK()
), blank())

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors