Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreShape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.
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!
Solved! Go to Solution.
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
Proud to be a Datanaut!
Can Text.Contains accept a variable instead of a literal as its input?
e.g.
if Text.Contains([Product], ColumnValue) or Text.Contains([Product], "*") then blah blah blah
Thank you
Yes, as long as the variable is a text-type scalar.
Pete
Proud to be a Datanaut!
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
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
Proud to be a Datanaut!
User | Count |
---|---|
24 | |
13 | |
11 | |
10 | |
7 |
User | Count |
---|---|
43 | |
26 | |
21 | |
16 | |
12 |