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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

SWITCH(TRUE not operating as intended when using &&/||

The logic I am attempting to follow is:

 

If column 1 equals True then "Some Designation 1"

If column 2 equals True then "Some Designation 2"

If Column 3 equals "Some Value1" AND Column 4 equals 1 or 2 or 3 or 4 or 5 Then "Some Designation 3"

If Column 3 equals "Some Value2" AND Column 4 equals 1 or 2 or 3 or 4 or 5 Then "Some Designation 3"

Else "Undefined"

 

I cannot seem to get my SWITCH Correct:

Designation = SWITCH(
    TRUE(),
    'Table'[column1] = True, "Some Designation 1",
    'Table1'[Column2 = True, "Some Designation 2",
    'Table1'[column3] = "Some Value 1" 
    && 'Table1'[Column 4] = "1"||
        'Table1'[Column 4] = "2" || 
        'Table1'[Column 4] = "3" || 
        'Table1'[Column 4] = "4" || 
        'Table1'[Column 4] = "5" || 
        'Table1'[Column 4] = "6" || 
        'Table1'[Column 4] = "7" || 
        'Table1'[Column 4] = "8", 
        "Some Designation 3",
        'Table1'[column3] = "Some Value 2" 
    && 'Table1'[Column 4] = "1"||
        'Table1'[Column 4] = "2" || 
        'Table1'[Column 4] = "3" || 
        'Table1'[Column 4] = "4" || 
        'Table1'[Column 4] = "5" || 
        'Table1'[Column 4] = "6" || 
        'Table1'[Column 4] = "7" || 
        'Table1'[Column 4] = "8", 
        "Some Designation 3", 
        "Undefined")

 

5 REPLIES 5
Anonymous
Not applicable

Check the rules on operation precedence. Your logic certainly is not
what you had in mind. Best advice you can get is: ALWAYS USE PARENTHESES to explicitly say to the computer what you want. Another good advice is: observe data types rigorously.

And the last one... What does it mean "I can't get my SWITCH correct"? You did not tell us the reason and expecting us to give you an answer...

Would you mind telling us why the SWITCH is not returning what you want?

Thanks.

Best
D.
Anonymous
Not applicable

In the code below, the bolded part is operating incorrectly:

Designation = SWITCH(
    TRUE(),
    'Table'[column1] = True, "Some Designation 1",
    'Table1'[Column2 = True, "Some Designation 2",
    'Table1'[column3] = "Some Value 1" 
    && 'Table1'[Column 4] = "0050y00000BqlMYAAZ"||
        'Table1'[Column 4] = "0051A00000DDSCrQAP" || 
        'Table1'[Column 4] = "00580000003E3aSAAS" || 
        'Table1'[Column 4] = "005C0000003FsM6IAK" || 
        'Table1'[Column 4] = "005C0000003FsMKIA0" || 
        'Table1'[Column 4] = "005C0000003FsMRIA0" || 
        'Table1'[Column 4] = "005C0000005zJ0DIAU" || 
        'Table1'[Column 4] = "005C00000062BkNIAU", "Some Designation 3"
        "Undefined")

Instead of checking both conditions: IF column 3 equals contains "this value" AND IF column 4 contains "one of these 8 values" then it should be labeled "Some designation 3"

 

It is checking if either of them are true.

 

if(x=1 AND (y = 1 OR 2 OR 3 etc...)) then z

 

Additionally, you can use IN

 

'Table1'[column3] = "Some Value 1" 
    && 'Table1'[Column 4] in { "0050y00000BqlMYAAZ",
         "0051A00000DDSCrQAP" , 
         "00580000003E3aSAAS" , 
         "005C0000003FsM6IAK" , 
         "005C0000003FsMKIA0" , 
         "005C0000003FsMRIA0" , 
         "005C0000005zJ0DIAU" , 
         "005C00000062BkNIAU" }

 

Love hearing about Power BI tips, jobs and news?
I love to share about these - connect with me!

Stay up to date on  linkedin-logo.png
Read my blogs on  powerbi.tips_.png

Remember to spread knowledge in the community when you can! tu.png



Did I answer your question? Mark my post as a solution! Proud to be a Super User!


Connect with me!
Stay up to date on  
Read my blogs on  



Anonymous
Not applicable

As I said: you have to use parentheses. && and || have the same precedence, so A && B || C is calculated as (A && B) || C, not as A && (B || C).

Best
D.

Anonymous
Not applicable

Unfortunately I do not understand what you mean by "Use Parentheses." When I introduce parentheses into my code as if it is an order of operations defining statement the code errors out.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.