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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

How can I have an M Query Text.Contains function search for multiple possible words in a field?

I would like to have a Text.Contains that searches Column A for "Example" OR "Examples" OR "Examples2". I am sure it is staring me in the face but I cannot figure out how to do it.

1 ACCEPTED SOLUTION

Hi @Anonymous ,

Please try this:

if Text.Contains([Column1],"Example") = true then [Column1] else null

2.PNGThe function of Text.Contains will search out all the data which contains the key word. So you just need to write Text.Contains one time.

 

If you want to filter data, you could try this:

= Table.SelectRows(#"Changed Type", each Text.Contains([Column1], "Example"))

3.PNG

Best Regards,

Xue Ding

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

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

View solution in original post

5 REPLIES 5
Pacool
New Member

Hi,

 

Put these Example(s) words you want to find in strings in lists and then use the List.MatchesAny function.

Like in the following example:

Define a table with your keywords... (Example,Examples,sample...)

Transform_Keywords_list_in_list =
Table.TransformColumns
(
Source
,{
"Keywords list"
,each Text.Split(_, ",")
}
),

Main_Data =
Table.AddColumn
(
Main_Data_Table
,"Returned_Text"
,(MAIN)=>
let
Buffered_Keywords_list_in_list = Table.Buffer(Keywords_list_in_list ),

FilteredTable = Table.SelectRows
(
Buffered_Keywords_list_in_list
,(KEYWORDS)=>
List.MatchesAny(KEYWORDS[Keywords list], each Text.Contains(MAIN[String_to_test], _, Comparer.OrdinalIgnoreCase))
),
selectValue = Table.First(FilteredTable)[Value_to_return] // or you can return directly the table... selectValue = FilteredTable
in
selectValue, type text  // or if you need the table returned  selectValue, type table
),

 

JasonTX
Resolver I
Resolver I

If you are trying to perform this on a table, you would like to use something like:

 

#"Filtered Rows" = Table.SelectRows(table, each( Text.Contains([ColumnA], "Executive") or Text.Contains([ColumnA], "General") ))

 

 

Regards

Anonymous
Not applicable

@JasonTX, thanks for the suggestion. I have been doing it that way, but I am hoping I can cut out the repetitious "Text.Contains".

Hi @Anonymous ,

Please try this:

if Text.Contains([Column1],"Example") = true then [Column1] else null

2.PNGThe function of Text.Contains will search out all the data which contains the key word. So you just need to write Text.Contains one time.

 

If you want to filter data, you could try this:

= Table.SelectRows(#"Changed Type", each Text.Contains([Column1], "Example"))

3.PNG

Best Regards,

Xue Ding

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

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

Hi,

 

Put these Example(s) words you want to find in strings in lists and then use the List.MatchesAny function.

Like in the following example:

Define a table with your keywords... (Example,Examples,sample...)

Transform_Keywords_list_in_list =
Table.TransformColumns
(
Source
,{
"Keywords list"
,each Text.Split(_, ",")
}
),

Main_Data =
Table.AddColumn
(
Main_Data_Table
,"Returned_Text"
,(MAIN)=>
let
Buffered_Keywords_list_in_list = Table.Buffer(Keywords_list_in_list ),

FilteredTable = Table.SelectRows
(
Buffered_Keywords_list_in_list
,(KEYWORDS)=>
List.MatchesAny(KEYWORDS[Keywords list], each Text.Contains(MAIN[String_to_test], _, Comparer.OrdinalIgnoreCase))
),
selectValue = Table.First(FilteredTable)[Value_to_return] // or you can return directly the table... selectValue = FilteredTable
in
selectValue, type text  // or if you need the table returned  selectValue, type table
),

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.