cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
jxzn
New Member

using if(text.Contains) for multiple conditions in Power Query M

Hi there

 

I am trying to make a custom column by using an if() statement to pass an existing column through more than one text.Contains condition, and then return a string.

 

I have tried the below with no luck:

 

 

 

if text.Contains([Product], "AB") & text.Contains([Product], "CD") then "EF"

 

 

 

and

 

 

 

if text.Contains([Product], "AB" & "CD") then "EF"

 

 

I've found similar questions online but all of the resources I can find are using ><= and integers or are just for a single condition.

 

Any help on a solution would be much appreciated.

Thanks in advance!

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

@jxzn 

 

The correct syntax in Power Query would be as follows. Pay very close attention to the capitalisation as M code is entirely case-sensitive:

if Text.Contains([Product], "AB") and Text.Contains([Product], "CD")
then "EF"
else //your escape value goes here, like null or "Error" or similar

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

3 REPLIES 3
v-stephen-msft
Community Support
Community Support

Hi @jxzn ,

 

I agree with @BA_Pete 's solution. Has your problem been solved?

If it is resolved, please mark the helpful reply as an answer, and more people will benefit.

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Stephen,

 

What about in the case where you have two words in one column and you would like the new column to show both separate by a comma under an specific order?

For instance in one colum you could have sizes "small, medium, large" (but you can have the three words in one string of text inside the column) and you would like to have the three words separated by comma and the last by an "and" like "Small, medium and large".

 

Thank you!

 

Best

 

Alvaro

BA_Pete
Super User
Super User

@jxzn 

 

The correct syntax in Power Query would be as follows. Pay very close attention to the capitalisation as M code is entirely case-sensitive:

if Text.Contains([Product], "AB") and Text.Contains([Product], "CD")
then "EF"
else //your escape value goes here, like null or "Error" or similar

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors