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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
ValeriaBreve
Post Patron
Post Patron

List.FindText with items from a list?

Hello,

I have 2 lists:

ListData

ListFilter

both containing text strings.

I would like to find any item in ListData that contains any part of a string from ListFilter.

ex.

ListData: {"red apple", "blue apple", "green banana", "red pear"}

ListFilter:{"apple","pear"}

 

Desired result:  {"red apple", "blue apple", "red pear"}

 

I have tried List.FindText which works wonderfuly with an unique text - but how do you adapt it to scanning through a list?

 

Thanks a lot!

Kind regards

Valeria

1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

Another approach, using List.Accumulate to cycle through the ListFilter:

let
    ListData= {"red apple", "blue apple", "green banana", "red pear"},
    ListFilter={"apple","pear"},
    filter = List.Accumulate(
        ListFilter,
        {},
        (s,c)=> s & List.FindText(ListData,c))    
in
    filter

View solution in original post

10 REPLIES 10

Hi,
How I will handle this.
let
Source = {"red apple", "blue apple", "green banana", "red pear"},
Custom1 = {"apple","pear"},
Custom2 = List.Select(Source, each List.AnyTrue(List.Transform(Custom1, (substring) => Text.Contains(_, substring))))
in
Custom2

Muhammad_Ahmed_0-1724420868187.png

 




Ahmedx
Super User
Super User

pls try

let
       f=(x)=> List.Select(x, (y)=> List.Count( Splitter.SplitTextByAnyDelimiter( List.Transform(ListFilter,Text.Lower))(y))>1),
     Source = {"red apple", "blue apple", "green banana", "red pear"},
    Custom1 = f(Source)
in
  Custom1
ronrsnfld
Super User
Super User

Another approach, using List.Accumulate to cycle through the ListFilter:

let
    ListData= {"red apple", "blue apple", "green banana", "red pear"},
    ListFilter={"apple","pear"},
    filter = List.Accumulate(
        ListFilter,
        {},
        (s,c)=> s & List.FindText(ListData,c))    
in
    filter

@ronrsnfld  @ZhangKun both your solutions work but only partially for me (which I know it's impossible). Still In my filter list I have items like "Q1". In my data list I have an item "2024 Q1" and it won't be returned. I checked the spelling, no trailing spaces...do you have an idea what might be happening? Thanks!

There may be something wrong with how you implemented my solution.

Adding the item "2024 Q1" to ListData and "Q1" to ListFilter includes "2024 Q1" in the returned list.

 

 

let
    ListData= {"2024 Q1","red apple", "blue apple", "green banana", "red pear"},
    ListFilter={"apple","Q1"},
    filter = List.Accumulate(
        ListFilter,
        {},
        (s,c)=> s & List.FindText(ListData,c))    
in
    filter

 

 

Results (as expected):

ronrsnfld_0-1724415866891.png

 

 

 

@ronrsnfld @ZhangKun Thanks! I don't know what was happening... I did a couple of transformations to the ListData - which change nothing to items like "2024 Q1" - and now it works. Never seen this before, and I don't understand it. Anyway - again thanks - with this it works perfeclty 🙂 

My answer did not use the List.FindText function (it is easier to use List.FindText), so I deleted the answer. If you still have problems, you should provide the data row in question, such as "2024 Q1" as you said.

Hi @ZhangKun thanks but what a pity! Your solution was working perfectly as well and was a nice alternative 🙂 Thanks!

Ahmedx
Super User
Super User

Can you share sample data (ListData and  ListFilter) ?

@Ahmedx Hello,

ListData: {"red apple", "blue apple", "green banana", "red pear"}

ListFilter:{"apple","pear"}

 

Desired result:  {"red apple", "blue apple", "red pear"}

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors