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
Anonymous
Not applicable

DAX Switch True

I am using a Switch True evaluation and am getting all results back in the expected manner, with the exception of one item. I have tried moving the line to a different spot in the evaluation, but then I lose others. Is it possible this is an order of evaluation problem? The red font is what is not getting picked up, even though I know I have expected results in that category. 

 

Missed Obligation =
SWITCH(
TRUE(),
'Spares MGMT'[Line_Released]="1" && 'Spares MGMT'[Error_any]= "0" && 'Spares MGMT'[Spares_DM]="01_SPARES_MISSED_OBLIGATION" &&'Spares MGMT'[UX300]="0" && 'Spares MGMT'[EXPORT]="0", "Domestic",
'Spares MGMT'[Line_Released]="1" && 'Spares MGMT'[Error_any]= "0" && 'Spares MGMT'[Spares_DM]="01_SPARES_MISSED_OBLIGATION" && 'Spares MGMT'[UX300]="0" && 'Spares MGMT'[EXPORT]="1", "Export",
'Spares MGMT'[Line_Released]="1" && 'Spares MGMT'[Error_any]= "0" && 'Spares MGMT'[Spares_DM]="01_SPARES_MISSED_OBLIGATION" && 'Spares MGMT'[UX300]="1", "UX300",
'Spares MGMT'[Line_Released]="1" && 'Spares MGMT'[Error_any]= "0" && 'Spares MGMT'[Spares_DM]="01_SPARES_MISSED_OBLIGATION", "NonError",
'Spares MGMT'[Line_Released]="1" && 'Spares MGMT'[Error_any]= "1" && 'Spares MGMT'[Spares_DM]="01_SPARES_MISSED_OBLIGATION", "Error"
,"N/A")
5 REPLIES 5
Anonymous
Not applicable

Under SWITCH you always have to place the MOST SPECIFIC condition first.

Best
D
sturlaws
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

the statements in SWITCH is evaluated statement by statement. If it encounters a statement which is true, it evaluates the corresponding expression and then quits the evaluation of the remaining statements. In your case, your first statement is 

'Spares MGMT'[Line_Released] = "1"
        && 'Spares MGMT'[Error_any] = "0"
        && 'Spares MGMT'[Spares_DM] = "01_SPARES_MISSED_OBLIGATION"
        && 'Spares MGMT'[UX300] = "0"
        && 'Spares MGMT'[EXPORT] = "0", "Domestic",

 

while the one you say is missing is

'Spares MGMT'[Line_Released]="1" 
&& 'Spares MGMT'[Error_any]= "0" 
&& 'Spares MGMT'[Spares_DM]="01_SPARES_MISSED_OBLIGATION", "NonError",

 

If 'Spares MGMT'[Line_Released]="1" && 'Spares MGMT'[Error_any]= "0" && 'Spares MGMT'[Spares_DM] = "01_SPARES_MISSED_OBLIGATION" evaluates to true, as well 'Spares MGMT'[UX300] = "0"
&& 'Spares MGMT'[EXPORT] = "0", evaluates to true, it will never reach the statement you say is missing.

And if you move the "missing statement" to the top of your statements, when this evaluates to true, the rest of the statements will not be evaluated. So you might have to refine you logic a little. Or perhaps split it into two columns

 

Cheers,
Sturla

harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

 

I think  for Non Error     Spares MGMT'[UX300] is  BLANK ().

 

 

Try this :

 

 

Missed Obligation =
VAR a = 'Spares MGMT'[Line_Released] = "1"
    && 'Spares MGMT'[Error_any] = "0"
    && 'Spares MGMT'[Spares_DM] = "01_SPARES_MISSED_OBLIGATION"
    && 'Spares MGMT'[UX300] = "0"
RETURN
    SWITCH (
        TRUE (),
        'Spares MGMT'[Line_Released] = "1"
            && 'Spares MGMT'[Error_any] = "0"
            && 'Spares MGMT'[Spares_DM] = "01_SPARES_MISSED_OBLIGATION"
            && 'Spares MGMT'[UX300]
                = BLANK (), "NonError",
        a
            && 'Spares MGMT'[EXPORT] = "0", "Domestic",
        a
            && 'Spares MGMT'[EXPORT] = "1", "Export",
        a
            && 'Spares MGMT'[UX300] = "1", "UX300",
        'Spares MGMT'[Line_Released] = "1"
            && 'Spares MGMT'[Error_any] = "1"
            && 'Spares MGMT'[Spares_DM] = "01_SPARES_MISSED_OBLIGATION", "Error",
        "N/A"
    )

 

 


Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

 

 

Anonymous
Not applicable

It's easy to troubleshoot. Make each and every condition into its own calculated column and output its value. You'll see then exactly what you get from each condition on the lines you think the SWITCH is not working. I assure you that it's a problem with your logic, not with SWITCH.

Best
D
Anonymous
Not applicable

So, I took the same exact logic and entered it as it's own calculated column and it gave the expected result. I did not change anything in the logic, just put it by itself. So, what's next? If I put it back in with the other statements, it's still not working, even though it is by itself. 

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