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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.