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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
rjennings
Regular Visitor

Output calculated table of top 3 employees for each metric

Hi everyone, so this is a really tricky problem that I've been stuck on all week... I have a dataset of orders and the employees who processed them where we calculate KPIs. I would like to make a report of "Top 3 Employees by Metric" where I have bar charts with the number 1, 2, and 3 employees for a given metric (think olympic podium style) on the x-axis, and their values as 1 (for the number 1 employee), 2 (for number 2), and 3 (for number 3). I'll just stick with three metrics for simplicity's sake, here is the starting data table:

 

 

Order NumberEmployeeItem CountCancelled CountReturn Count
1Joe321
2Bob502
3Sue211

 

And here is the output table I would like to achieve:

 

RankItem CountCancelled CountReturn Count
1BobBobJoe
2JoeSueSue
3SueJoe

Bob

 

As you can tell there are situations where I need to break ties (e.g. in the return count metric, Joe and Sue are tied) and I would like to break the ties using the total Item Count column. I've tried using the RANKX and TOPN functions with no luck, though I'm probably doing something wrong. When I can get them to rank at all, many times they are all rank 1, or sometimes the ranks are clearly incorrect (like saying 4 is greater than 10). In addition this output needs to react to changing slicers on the page (e.g. someone choosing a new store with different employees, or a different date range). Any ideas? I need to get a draft of this out by tomorrow and have kinda exhausted all the other options. Thanks!

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi, @rjennings 

Please check the below picture and the sample pbix file's link down below.

 

Picture2.png

 

Item Count Rank Measure =
VAR selectrank =
SELECTEDVALUE ( Ranking[Rank] )
VAR newtable =
FILTER (
Data,
CALCULATE ( SUM ( Data[Item Count] ) )
= MINX (
TOPN ( selectrank, Data, CALCULATE ( SUM ( Data[Item Count] ) ), DESC ),
CALCULATE ( SUM ( Data[Item Count] ) )
)
)
RETURN
IF( ISFILTERED(Ranking[Rank]),
MAXX ( newtable, Data[Employee] )
)
 
 
Cancelled Count Rank Measure =
VAR selectrank =
SELECTEDVALUE ( Ranking[Rank] )
VAR newtable =
FILTER (
Data,
CALCULATE ( SUM ( Data[Cancelled Count] ) )
= MAXX (
TOPN (
selectrank,
Data,
CALCULATE ( SUM ( Data[Cancelled Count] ) ), ASC
),
CALCULATE ( SUM ( Data[Cancelled Count] ) )
)
)
RETURN
IF( ISFILTERED(Ranking[Rank]),
MAXX ( newtable, Data[Employee] )
)
 
 
Return Count Rank Measure =
VAR selectrank =
SELECTEDVALUE ( Ranking[Rank] )
VAR newtable =
FILTER (
Data,
100 * CALCULATE ( SUM ( Data[Return Count] ) )
+ 1 / CALCULATE ( SUM ( Data[Item Count] ) )
= MAXX (
TOPN (
selectrank,
Data,
100 * CALCULATE ( SUM ( Data[Return Count] ) )
+ 1 / CALCULATE ( SUM ( Data[Item Count] ) ), ASC
),
100 * CALCULATE ( SUM ( Data[Return Count] ) )
+ 1 / CALCULATE ( SUM ( Data[Item Count] ) )
)
)
RETURN
IF( ISFILTERED(Ranking[Rank]),
MAXX ( newtable, Data[Employee] )
)
 
 
 
 
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.