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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
luigiPulido_
New Member

Performance issue in List.Contains Step - 30 minutes for 500 records

In a previous post I asked how to get all the records where orders includes an specific product.

Example:

luigiPulido__2-1700013782841.png

Expected result if I'm looking for orders that include 'bbbb'

luigiPulido__3-1700013831207.png

Thanks to @AlienSx  for the answer.

 

But then I tried to filter all the table to get records where orders don't have the product 'bbbb'. This is the expected result

luigiPulido__4-1700014074533.png

 

and I achive this with the following code:

 

 

 

let
    Source = table,
    ordersToExclude = Table.SelectRows(Origen, (x) => x[Product] = "bbbbb")[Order],
    allOrders = Table.SelectRows(Origen, (x) => Text.Start(x[Order],1)="#" )[Order],
    ordersIwant = List.RemoveItems(allOrders,OrdersToExclude),
    removeDuplicates = List.Distinct(OrdersIwant),
    finalTable = Table.SelectRows(Source, (x) => List.Contains(removeDuplicates,x[Order]) )
in
    finalTable

 

 

 

The problem with that code is that it takes a lot of Time and resources for excecution. I run it with a file that only have 515 rows and it takes more than 30 minutes and almost 20GB of memory (not sure which memory). Insane

 

luigiPulido__1-1700013688657.png

 

My thoughts is that there is like a big loop in the finalTable step. That's why I apply the remove duplicates step but it still takes a lot of time. 

 

With my real data of 515 rows, after remove duplicates there is only like 90 unique orders without the 'bbbb' product.

 

So my questions are:

 

  • My assumption with the loop is correct and thats why is taking so much time or what is happening??
  • Do you see another posible solution?

 

2 REPLIES 2
AlienSx
Super User
Super User

Hello, @luigiPulido_ my 2c. While suggestion made by @watkinnc should definitely boost performance, I would also try alternative way to filter orders using Table.Group. Group your data by [Order] and create 2 aggregated columns:

1. all order items as {"all", each _}

2. logical test if products list contains unwanted item as {"test", each List.Contains(_[Product], "bbbb")}

Then filter test and expand all

watkinnc
Super User
Super User

Buffer those List.Contains, lad. Always buffer your List.Contains lists.

each List.Contains((List.Buffer(removeDuplicates, [Order]) 


You won't believe the difference. 

--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!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors