Forum Discussion
Measure - How to Rank a column by items
Hi all,
I am trying to summarize a table by ranking the cost.
Desired outcome:
-Only rank with the same "ID"
-The summarize table which only contains "Rank 1" or "Rank 2"
Here is what I am trying but NOT success:
Rank=RANKX(Filter(ALLSELECTED('Table'),'Table'[ID]='Table'[ID],CALCULATE(SUM('Table'[Cost])))
From
| ID | Name | cost | Rank |
| 1 | A | 10 | 2 |
| 1 | B | 8 | 1 |
| 2 | A | 5 | 1 |
| 2 | B | 8 | 2 |
| 3 | A | 2 | 1 |
| 3 | B | 4 | 2 |
| 4 | A | 6 | 2 |
| 4 | B | 5 | 1 |
Desired Outcome:
| ID | Name | cost | Rank |
| 1 | B | 8 | 1 |
| 2 | A | 5 | 1 |
| 3 | A | 2 | 1 |
| 4 | B | 5 | 1 |
Appreciate if any help!
Hi, ngct1112
It’s my pleasure to answer for you.
According to your description,I think you can create a measure, then use it in filter pane.
Like this:
Rank = RANKX ( FILTER ( ALL ( 'Table' ), 'Table'[ID] = SELECTEDVALUE ( 'Table'[ID] ) ), CALCULATE ( SUM ( 'Table'[Cost] ) ), , 1 )If it doesn’t solve your problem, please feel free to ask me.
Best Regards
Janey Guo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
6 Replies
- lbendlin
Super User
Here is a version that uses a Calculated Column (not a Measure!)
Rank = var tid = 'Table'[ID] return Rankx(filter('Table','Table'[ID]=tid),'Table'[cost]) - lbendlin
Super User
Please explain what you mean by "calculated column cannot be used in a slicer".
- v-janeyg-msft
Community Support
Hi, ngct1112
It’s my pleasure to answer for you.
According to your description,I think you can create a measure, then use it in filter pane.
Like this:
Rank = RANKX ( FILTER ( ALL ( 'Table' ), 'Table'[ID] = SELECTEDVALUE ( 'Table'[ID] ) ), CALCULATE ( SUM ( 'Table'[Cost] ) ), , 1 )If it doesn’t solve your problem, please feel free to ask me.
Best Regards
Janey Guo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- ngct1112
Post Patron
v-janeyg-msft it works. Great thanks with your help.