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

Power Query - Return true for each List value that is contained within a string in a text column

Power Query - Return true for each List value that is contained within a string in a text column

 

I have a column "Text_Column" that has text strings. 

I have a list that contains keywords that are within the Text_Column

 

All I want to do is to return true (or 1) if any of the list values are found in the Text_Column FOR EACH row

 

This seems like a common scenario but I can't figure it out. 

 

I was trying to use List.Contains but it doesn't work. This is what I would have thought should work. 

Table.AddColumn(Source, "LIST_VALUE_FOUND", each if List.Contains(MyList, [Text_Column]) then 1 else 0

 

Is this possible?? Thank you

 

  

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @Anonymous 

Try this, works for me.  If you can't adapt it to your situation, please post some sample data I can use.

 

let
    TextCol = {"a big banana", "a small orange", "a green pear", "four red apples", "a pink flamingo"},
    MyList = {"apple", "banana", "pear"},
    Source =  Table.FromList(TextCol, null, {"Strings"}),
    #"Added Custom" = Table.AddColumn(Source, "Check", (C) => List.AnyTrue(List.Transform(MyList, each Text.Contains(C[Strings], _))))
in
    #"Added Custom"

 

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

5 REPLIES 5
Anonymous
Not applicable

You can use:

Filtered=Table.AddColumn(LastStep, "NewColumnName", each Text.Contains([ColumnToFilter], List.Buffer(NameOfListWithStrings)))

mahoneypat
Microsoft Employee
Microsoft Employee

Please clarify if you are comparing lists on the same row.  Do both columns say "List" for each row?  If so, can use the List.ContainsAny function - List.ContainsAny([MyList], [Text_Column])

 

If they are actually text strings with a delimiter or if you are generating a list of all the rows in the Text_Column column, a different approach is needed.

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

You can use:

Table.SelectRows(LastStep, each Text.Contains([ColumnToFilter], List.Buffer(NameOfListWithStrings)))

edhans
Super User
Super User

List.Contains is an exact match. Does the item you are checking against exist in the list as a separate item, not within the items. So if you have the word Hello you are looking for, if the list has "Hello World" it will not find it. 

 

Text.Contains will - as that i searching for a string within a string.

 

Can you post some data with what you are trying to accomplish and we can help come up with a solution.

 

How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly
How to provide sample data in the Power BI Forum



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
PhilipTreacy
Super User
Super User

Hi @Anonymous 

Try this, works for me.  If you can't adapt it to your situation, please post some sample data I can use.

 

let
    TextCol = {"a big banana", "a small orange", "a green pear", "four red apples", "a pink flamingo"},
    MyList = {"apple", "banana", "pear"},
    Source =  Table.FromList(TextCol, null, {"Strings"}),
    #"Added Custom" = Table.AddColumn(Source, "Check", (C) => List.AnyTrue(List.Transform(MyList, each Text.Contains(C[Strings], _))))
in
    #"Added Custom"

 

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

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.

Top Solution Authors