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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
jhsimb
Frequent Visitor

List.Contains() is slow

I tried to filter a column based on a list

I used List.Contains() but it is very slow

 

= Table.SelectRows(Medidas, each (List.Contains(Resta,[Cliente])=true ))

 

Please your help with a faster List.Contains because after this step I need to collapse that column

Thanks

7 REPLIES 7
watkinnc
Super User
Super User

= Table.SelectRows(Medidas, each List.Contains(List.Buffer(Resta),[Cliente]))

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

@watkinnc I would List.Distinct(Resta) before buffering and buffer outside of Table.SelectRows. My tests show that List.Contains works even faster than List.PositionOf on the same data.

But the fastest one is to create a record with unique Resta data as field names and "true" as value then 

Table.SelectRows(values, each Record.FieldOrDefault(resta_record, Text.From([Cliente]), false))

watkinnc
Super User
Super User

Definitely use List.Buffer, as in each List.Contains(List.Buffer(LookupList), [Column])

 

ALWAYS use List.Buffer in your List.Contains!

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

I use List.Buffer and it works but after when I collapse that column, very slow again.

AlienSx
Super User
Super User

@jhsimb we don't see what is Resta. If it's a result of some transformation/calculation then try to List.Buffer it beforehand. I would also give a try to List.PositionOf alternative with Occurrence.First like this:

= Table.SelectRows(Medidas, each List.PositionOf(Resta_buffered, [Cliente], Occurrence.First) <> -1 ) where Resta_buffered = List.Buffer(Resta) outside of your expression. 

Rest is a table. A table that was transformed in a list using Convert to List.

How do I use List.Buffer in this case?

Thanks

slorin
Super User
Super User

Hi,

use Table.NestedJoin with JoinKind.Inner

 

= Table.NestedJoin(Medidas, {"Cliente"}, Table.FromColumns({Resta},{"Resta"}), {"Resta"}, "JoinColumn", JoinKind.Inner)

then remove column "JoinColumn"

Stéphane 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Kudoed Authors