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

Use Switch and OR

Hi, 

 

Ive got a problem. I want to get multiple rules in a switch statement.. But its not working, only if u use OR-statement i can add 1 more rule..

 

Sample of the data/formula(its anonymized):

TEST =
OR(SWITCH(
       TRUE(),
        SessionDetails[ReferredById]<>1073, 0,
        SessionDetails[User1Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816} ||
    SessionDetails[User2Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816}, 1,
        0
),  SWITCH(
       TRUE(),
        SessionDetails[ReferredById]<>231049, 0,
        SessionDetails[User1Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816} ||
     SessionDetails[User2Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816},
1,0
), SWITCH(
       TRUE(),
        SessionDetails[ReferredById]<>440190, 0,
        SessionDetails[User1Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816} ||
        SessionDetails[User2Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816}, 1,0
), SWITCH(
       TRUE(),
        SessionDetails[ReferredById]<>39050, 0,
        SessionDetails[User1Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816} ||
        SessionDetails[User2Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816},1,0)
 
There must be a better way, like :
TEST =
OR(SWITCH(
       TRUE(),
        SessionDetails[ReferredById]<>(1073,39050,440190,231049) 0,
        SessionDetails[User1Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816} ||
    SessionDetails[User2Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816}, 1,
        0)
 
To put all the "RefferedByID's" in the same line.. Please help
 
Thanks in advanced

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

"There must be a better way, like :
TEST =
OR(SWITCH(
       TRUE(),
        SessionDetails[ReferredById]<>(1073,39050,440190,231049) 0,
        SessionDetails[User1Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816} ||
    SessionDetails[User2Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816}, 1,
        0)"
 
Try
 
TEST =
SWITCH(
       TRUE(),
        NOT ( SessionDetails[ReferredById] IN { 1073,39050,440190,231049 } ), 0,
        SessionDetails[User1Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816} ||
    SessionDetails[User2Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816}, 1,
        0)
 

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

"There must be a better way, like :
TEST =
OR(SWITCH(
       TRUE(),
        SessionDetails[ReferredById]<>(1073,39050,440190,231049) 0,
        SessionDetails[User1Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816} ||
    SessionDetails[User2Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816}, 1,
        0)"
 
Try
 
TEST =
SWITCH(
       TRUE(),
        NOT ( SessionDetails[ReferredById] IN { 1073,39050,440190,231049 } ), 0,
        SessionDetails[User1Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816} ||
    SessionDetails[User2Id] IN {1028,383575,93233,1013,259006,274202,361428,1011,262816}, 1,
        0)
 
Anonymous
Not applicable

Thanks, this is exactly what i wanted. 

I was so close to the solution haha

AnthonyTilley
Solution Sage
Solution Sage

I have a template i use for adding a switch with muliple criteria 

 

you can replace the && with a || to get an or statment. and just use as many colunms as is needed 

test_Switch = SWITCH(TRUE(),
([Column1]=1 && [Column2]=2 && [Column3]=1 && Table1[Column4]=1), "option 1",
([Column1]=1 && [Column2]=4 && [Column3]=2 && Table1[Column4]=4), "option 2",
([Column1]=2 && [Column2]=5 && [Column3]=5 && Table1[Column4]=5), "option 3",
([Column1]=2 && [Column2]=8 && [Column3]=4 && Table1[Column4]=8),"option 4",
([Column1]=3 && [Column2]=7 && [Column3]=8 && Table1[Column4]=5), "option 5",
"option Default"
)

Power bi Switch.png
 
this is how i would attapt it for your needs
 
test_Switch = SWITCH(TRUE(),
(NOT Table1[Column4] in {1073,39050,440190,231049}), "Refered by Id option",
([Column1] in {1028,383575,93233,1013,259006,274202,361428,1011,262816} || [Column2] in {1028,383575,93233,1013,259006,274202,361428,1011,262816}), "option 1",
"option Default"
)
 
just match this to your colunms and add the out oputs you require




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

Proud to be a Super User!




Anonymous
Not applicable

Thanks for your reply, but this isnt working for me. Doesnt give the output i need..

Are you able to give some sample data showing the data you have and your desired outcome 

 

If you have a PBIX file that i could down load i can try and impliment this for you 

 

 





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

Proud to be a Super User!




Anonymous
Not applicable

 

Example.PNG

 

 

 

 

 

 

 

 

 

Give back a TRUE if ReferredID equals 1 of the 4 desired ID's and if the match with 1 of the UserID's...

If ReferredByID equals 1073 OR 440190 OR 39050 OR 28536 

AND UserID equals 1028 OR 383575 OR 93233 OR 1013 then TRUE

 

else will give back FALSE everytime. 

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