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
gerard-kouadio
Frequent Visitor

combine text.contains and or in M

Hello, I want to do something like this:

#"Colonne conditionnelle ajoutée" = Table.AddColumn(#"Type modifié", "New colonn", each if Text.Contains([colonne1], "xxx") then "x" else if Text.Contains([colonne1], "xxxy") then "x" else if Text.Contains([colonne1], "xxxd") then "x" else if Text.Contains([colonne1], "xxxg") then "x" else null). This code work well. But I have a lot of modalities and I want to use other code like this

 

#"Colonne conditionnelle ajoutée" = Table.AddColumn(#"Type modifié", "New colonn", each if Text.Contains([colonne1], "xxxx" or "xxxd" or "xxxg" or "xxxy") then "x" else null). It not working well and I need help to find the right code. Thanks a lot for your help

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

#"Colonne conditionnelle ajoutée" = Table.AddColumn(#"Type modifié", "New colonn", each if List.Contains({"xxx","xxxy","xxxd","xxxg"},[colonne1],(x,y)=> Text.Contains(y,x)) then "x" else null)

View solution in original post

3 REPLIES 3
wdx223_Daniel
Super User
Super User

#"Colonne conditionnelle ajoutée" = Table.AddColumn(#"Type modifié", "New colonn", each if List.Contains({"xxx","xxxy","xxxd","xxxg"},[colonne1],(x,y)=> Text.Contains(y,x)) then "x" else null)

Your code contains all the right elements, but this is exactly the one that works.

#"Colonne conditionnelle ajoutée" = Table.AddColumn(#"Type modifié", "New colonn", each if List.Contains({"xxx","xxxy","xxxd","xxxg"},[colonne1]) then "x" else null)

 

 

I know you used ,(x,y)=> Text.Contains(y,x)) for the explanations. Thank you so much

my code will give a "x" when [colonne1]="2123xxx212" or "zzzxxxydd", as long as it contains any string in the list.

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