Forum Discussion
SeGr
1 year agoHelper I
Ranking calculation
Hi, Here's what I'm working on: I have a hierarchy made up of Sub-Category and Resource, and both of them come from the same table. I’ve already calculated the rank based on cost for each level...
- 1 year ago
I fixed the calculation:
Here is the Code:
Ranking 2 =var Table1 =SUMMARIZECOLUMNS('Table'[Resouce],'Table'[SubCategory],"@Ranking",CALCULATE(RANKX(ALLSELECTED('Table'[Resource]),[Total Cost],,DESC),allselected('Table'[SubCategory])))returnminx(Table1,[@Ranking])
rohit1991
1 year agoSuper User
Hi SeGr ,
Here’s a dynamic approach you can use with DAX:
Resource Rank in SubCategory =
VAR RankingTable =
SUMMARIZECOLUMNS(
Table[Resource],
Table[SubCategory],
"@Ranking", RANKX(
ALLSELECTED(Table[Resource]),
[Total Cost], , DESC
)
)
RETURN
MINX(
FILTER(
RankingTable,
RankingTable[SubCategory] = SELECTEDVALUE(Table[SubCategory])
),
[@Ranking]
)
This measure creates a virtual table of every Resource/Sub-Category combination and calculates the rank for each resource based on [Total Cost]. Then, it returns the rank for the relevant Sub-Category in your visual, even when Resource isn’t included. If you want to show the top or average resource rank within each Sub-Category, you can swap out MINX for MAXX or AVERAGEX as needed. Make sure your [Total Cost] measure works at the correct granularity and your relationships are set up properly. If you have ties, MINX just gives the smallest rank (i.e., top performer).
SeGr
1 year agoHelper I
I fixed the calculation:
Here is the Code:
Ranking 2 =
var Table1 =
SUMMARIZECOLUMNS(
'Table'[Resouce],
'Table'[SubCategory],
"@Ranking",
CALCULATE(
RANKX(
ALLSELECTED('Table'[Resource]),
[Total Cost],,DESC
),
allselected('Table'[SubCategory])
)
)
return
minx(
Table1,
[@Ranking]
)