How to calculate top 10 without running out of memory

martingaleh

Board Regular
Joined
Jul 18, 2011
Messages
83
I have 1 table with only 116k rows (Not 116M) and its broken down by customer |sales| invoice number
I want a table that aggregates sales by customer and I want it to just show the top 10 customers. Here's my dax:
sAmt = sum(sales)
calculate([sAmt],filter(table[customer],RANKX(all(table[customer]),abs([sAmt]))<=10))
which failed miserably because it filtered nothing and gave me every amount.

Then I tried filter(all(table[customer]),rankx(all(table[customer]),abs]),abs([sAmt]))<=10))

which filtered nothing

but when I tried addcolumns(all(table[customer]),"rank",rankx(all(table[customer]),abs([sAmt])))

The rank is right. Maybe the filter context inside filter is different from the one with addcolumns

A suggested syntax here:
https://powerpivotpro.com/2014/11/displaying-top-n-bottom-n-and-all-others/

would be
filter(table,rankx(all(table[customer]),abs]),abs([sAmt]))<=10))

but filter would iterate on every single row in the table which is 116k. Plus I thought calculate works in that filter provides a table of 1 column of just the customers I want and then calculate calculates the value of just those customers
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Never mind, I think I figured it out. filter(all(kimurasan[company]),calculate(rankx(all(kimurasan[company]),abs([sAmtKimurasanInvoicesMinuslatest])))<10)
Holy god, this is a hard language. At least in javascript, you can look through the scope chain to determine the scope. It's almost impossible to figure out the filter context and which fucntions change what filter context

oh and, of course, if you're interested in a table where company is the row filter, you have to keep it:
calculate([sAmt],keepfilters(filter(table[customer],RANKX(all(table[customer]),abs([sAmt]))<=10)))

can you image tableau with subquery language this complicated?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,674
Members
449,463
Latest member
Jojomen56

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top