Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How to aggregate rankings using a measure

Hi,

 

I have the folloing ranking information:

 

EmployeeCategoryScore
A1100
B180
C160
D140
E120
A250
B260
C290
D280
E2100
F270
A380
B390
C3100

 

The RANKX measure would allow me to do something like

 

Category 1
EmployeeScoreRank
A1001
B802
C603
D404
E205

 

Category 2
EmployeeScoreRank
A506
B605
C902
D803
E1001
F704

 

Category 3
EmployeeScoreRank
A803
B902
C1001

 

But I am trying to aggregate rankings based on Employee, i.e.:

 

Employee A
CategoryScoreRank
11001
2506
3803

 

Any ideas in how to achieve the above ranking summary using measure? I want everything to be done in measures (because I have other slicers affectings the score results so it is impossible to store it dynamically in a table).

 

Much appreciated!!!

 

 

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@Anonymous - After thinking about this a bit more, I came up with this:

 

Measure 9 = 
VAR __employee = MAX('Table10'[Employee])
VAR __category = MAX('Table10'[Category])
VAR __table = SUMMARIZE(ALL('Table10'),[Employee],[Category],"__score",SUM('Table10'[Score]))
VAR __table1 = FILTER(__table,[Category] = 1)
VAR __table1a = ADDCOLUMNS(__table1,"__rank",RANKX(__table1,[__score],,DESC))
VAR __table2 = FILTER(__table,[Category] = 2)
VAR __table2a = ADDCOLUMNS(__table2,"__rank",RANKX(__table2,[__score],,DESC))
VAR __table3 = FILTER(__table,[Category] = 3)
VAR __table3a = ADDCOLUMNS(__table3,"__rank",RANKX(__table3,[__score],,DESC))
VAR __tableRank = UNION(__table1a,__table2a,__table3a)
RETURN
MAXX(FILTER(__tableRank,[Employee]=__employee && [Category] = __category),[__rank])

See Page 5 of attached.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

@Anonymous - After thinking about this a bit more, I came up with this:

 

Measure 9 = 
VAR __employee = MAX('Table10'[Employee])
VAR __category = MAX('Table10'[Category])
VAR __table = SUMMARIZE(ALL('Table10'),[Employee],[Category],"__score",SUM('Table10'[Score]))
VAR __table1 = FILTER(__table,[Category] = 1)
VAR __table1a = ADDCOLUMNS(__table1,"__rank",RANKX(__table1,[__score],,DESC))
VAR __table2 = FILTER(__table,[Category] = 2)
VAR __table2a = ADDCOLUMNS(__table2,"__rank",RANKX(__table2,[__score],,DESC))
VAR __table3 = FILTER(__table,[Category] = 3)
VAR __table3a = ADDCOLUMNS(__table3,"__rank",RANKX(__table3,[__score],,DESC))
VAR __tableRank = UNION(__table1a,__table2a,__table3a)
RETURN
MAXX(FILTER(__tableRank,[Employee]=__employee && [Category] = __category),[__rank])

See Page 5 of attached.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi Greg, thanks for your help! May I ask what is the use of MAX function in your measure of '_employee' and '_category'?

Greg_Deckler
Super User
Super User

Perhaps something along the lines of:

 

Table = 
VAR __table = SUMMARIZE('Table10',[Employee],[Category],"__score",SUM('Table10'[Score]))
VAR __table1 = ADDCOLUMNS(__table,"__rank",RANKX(__table,[__score],,DESC))
RETURN
__table1

You could grab your Employee and Category and filter down __table1 in a measure.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.