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.
I'm a beginner and I'm trying to find out the year the first time a customer bought (and total of all purchases that year).
What is my 'mytable' in this your example? I even tried renaming my sheet 'mytable'.
I am getting this error when I try your solution: Token literal expected