Forum Discussion
Showing Top N values per category based on a value
- 8 years ago
I managed to fins a way to do this thankfully:
Step #1: I went into query editor and sorted my table high to low by the value column and then added an index column called Index and applied changes.
Step #2: I added a calculated column called rank using this formula: Rank = RANKX(FILTER('mytable','myTable'[uniqueProductCode]=EARLIER('myTable'[uniqueProductCode])),'myTable'[Index],,ASC)
Step #3: I selected the modeling tab, clicked New Table and used the following formula for my new calculated table:
Top 1000 Products =
SELECTCOLUMNS (
FILTER ( 'myTable', 'myTable'[Rank] <= 1000 ),
"Product", 'myTable'[Product],
"Phrase", 'myTable'[Phrase],
"UniqueProductCode", 'myTable'[uniqueProductCode],
"Value", [Sum of Value],
"Rank", 'myTable'[Rank]
)I can then adjust the table as needed by changing "<= 1000" to represent the top N values per category. Hope this helps others if they are looking for the same solution.
Hi Sam thanks for your response, unfortunately that wont work for me as Im trying to get the Top N by category with all categories listed in the same table. I did happen to find the answer though so will post my solution for any who are also looking