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
ghdunn
Helper III
Helper III

conditional column: if [field] in (“a”,”b”,”c”) then x else y

I am adding a conditional column to a data table and find that If [field] = “a” then 1 else If [field] = “b” then 2 else..... etc etc ...works fine. However... I would like to use an ‘in’ condition like MS Access If [field] IN (“a”,”b”,”c”) then 3 else.... Looked extensively on web but nothing seems to deal with this. Thanks
1 ACCEPTED SOLUTION
LivioLanzo
Solution Sage
Solution Sage

Hello @ghdunn

 

you can use the List.Contains function: https://docs.microsoft.com/en-us/powerquery-m/list-contains

 

if List.Contains({"a","b","c"}, [field1]) then "it contains it" else "it does not contain it"

 


 


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


Proud to be a Datanaut!  

View solution in original post

2 REPLIES 2
LivioLanzo
Solution Sage
Solution Sage

Hello @ghdunn

 

you can use the List.Contains function: https://docs.microsoft.com/en-us/powerquery-m/list-contains

 

if List.Contains({"a","b","c"}, [field1]) then "it contains it" else "it does not contain it"

 


 


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


Proud to be a Datanaut!  

Thanks..I did look at ListContains but just didn't twig that the syntax would work like that...was so convinced that there would be some 'IN' condition hidden in 'M' 🙂  My bad.   Thanks for super quick response.

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.