Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Einomi
Helper V
Helper V

Text.Contain or List.Contain

Hello

 

I have the following column in my table

 

Description
Hello AADF 456
Hello GTYH 456
Hello AADF 987
Hello GTYH 987

 

I would like please a M code to be able to identify the Hello, I mean I would like to have this

 

If my column contains Hello and 456 I want H1

If my column contains Hello and 987 I want H2

 

DescriptionOutput
Hello AADF 456H1
Hello GTYH 456H1
Hello AADF 987H2
Hello GTYH 987H2

 

I found that Text.Contains works only for one word, here I am looking for two string of characters which may not foloow each other

 

I hope I was clear enough and it makes sense

 

Thanks All

1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

If you are looking for multiple words in a column, and then outputting a code, the "best" way to do that probably depends on the nature of your actual problem.

 

One "simple" method is with a Custom Column using List.ContainsAll:

if List.ContainsAll(Text.Split([Description]," "),{"Hello","456"}) 
   then "H1" 
   else if List.ContainsAll(Text.Split([Description]," "), {"Hello","987"}) 
   then "H2" 
   else null

However, if you have many possible combinations, using a lookup table approach might be more flexible.

View solution in original post

3 REPLIES 3
ronrsnfld
Super User
Super User

If you are looking for multiple words in a column, and then outputting a code, the "best" way to do that probably depends on the nature of your actual problem.

 

One "simple" method is with a Custom Column using List.ContainsAll:

if List.ContainsAll(Text.Split([Description]," "),{"Hello","456"}) 
   then "H1" 
   else if List.ContainsAll(Text.Split([Description]," "), {"Hello","987"}) 
   then "H2" 
   else null

However, if you have many possible combinations, using a lookup table approach might be more flexible.

Einomi
Helper V
Helper V

Hi, @AlexisOlson 

 

I am sorry for the delay, I did not get notifications of your answer.

 

If in my column [Tableau C_0. Transaction Description] we have the string "Hello" and the string "456" then H1

 

 

I am attaching a picture of my M code, I am not sure if I managed to work it out with your code

 

e2s5.PNG

AlexisOlson
Super User
Super User

You could use multiple Text.Contains functions.

if Text.Contains([Description], "Hello") then
    if      Text.Contains([Description], "456") then "H1"
    else if Text.Contains([Description], "987") then "H2"
else "Other"

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.