Forum Discussion
Dynamic Ranking of Top 10 and Others in Matrix
- 7 years ago
Hello kemppaik
I have used the following method in a couple of models with success.
First, we need table that has the unique list of items you want to rank and an additional row for "Other", we can get that with a simple calculated table.
Customers = UNION ( DISTINCT ( 'Details'[Customer Name] ), ROW ( "Customer Name", "Other" ) )This table we join back into Details on the [Customer Name] field.
Then we can write the measure that calcs our TopN customers and other.
Top N = VAR Top_N = CALCULATETABLE ( Customers, TOPN ( 5, ALL ( Customers ), CALCULATE ( [Total Amount], ALL ( 'Date' ) ) ) ) RETURN IF ( NOT ISFILTERED ( Customers[Customer Name] ), CALCULATE ( [Total Amount], ALL ( Customers ) ), IF ( SELECTEDVALUE ( Customers[Customer Name] ) = "Other", CALCULATE ( [Total Amount], EXCEPT ( ALL ( Customers ), Top_N ) ), CALCULATE ( [Total Amount], INTERSECT ( Customers, Top_N ) ) ) )Finally we need a measure to do the sorting of our customers since we want the Top customers sorted descending the other on the bottom.
TopN Sort = IF ( SELECTEDVALUE ( Customers[Customer Name] ) = "Other", 0, [Top N] )
The sorting part is a bit ugly but it is the only way I know to do it right now. We add the TopN Sort measure into the matrix, sort the matrix by TopN Sort and collapse all the columns of TopN Sort so you don't see them. This is all so we get the following:
I have uploaded my sample .pbix file here Top 5 Other sorted.pbix
In my example I only did the top 5, you just need to change the highlighted number.
- 7 years ago
Thanks for the response jdbuchanan71 . I was able to get this to work. I tried a Top N calculation before but didn't get this far because I didn't do the Top N calculation correctly - I was making it too complex.
Any result? I am trying to do a simular approach? Re: Dynamic Table Top10 Grouping & Other - Microsoft Fabric Community