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

Measure difference between rows in scoreboard

I'm trying to make a dynamic Scoreboard for a sales department and everything works fine except for one thing: calculating the differences for each line.

I know that i could do it with Power Query by using two index columns and then just merge them, but that would make it static. I want to be able to compare different groups of people and it should automaticly update the rank and differences in the current list.

 

The list looks something like this at the moment. In the example I have choosen 6 members to compare but I might need to switch them out and the values should then be calculated based on the new table.

Power BI - Picture 1.png

 

 

 

 

 

 

 

 

 

Details

Rank = RANKX(ALLSELECTED('Sales people');[Sum];[Sum];DESC;Dense)

Sum = This is just a measure that adds a couple of sum-functions from various tables

The Diff Sum to Rank 1 is first a measure that calculates the top sum and then it subtracts the sales persons sum from that:

Sum for Rank 1 = CALCULATE(MAXX('Sales people';[Sum]);ALLSELECTED('Salespeople'))

Diff Sum to Rank 1 = [Sum]-[Sum for Rank 1]

 

So far so good! What I want now is a measure that calculates the difference between each sales person and the one above in the score list.

This is how I would have done it with Excel if I had a static list.

Power BI - Picture 2.png

 

 

 

 

 

 

 

Any ideas?

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @Anonymous

 

My answer below is modelled on the useful patterns in this article
https://www.sqlbi.com/articles/displaying-nth-element-in-dax/

 

Diff to next person =
VAR CurrentRank = [Rank]
VAR CurrentSum = [Sum]
VAR NextPerson =
    FILTER ( ALLSELECTED ( 'Sales people' ); [Rank] = CurrentRank - 1 )
VAR NextPerson_Sum =
    MINX ( NextPerson; [Sum] )
RETURN
    IF ( NOT ISBLANK ( NextPerson_Sum ); CurrentSum - NextPerson_Sum )

This formula basically filters Sales People to the current rank minus 1, and evaluates Sum for that sales persion (using MINX in case of tied ranks for the next person).

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi @Anonymous

 

My answer below is modelled on the useful patterns in this article
https://www.sqlbi.com/articles/displaying-nth-element-in-dax/

 

Diff to next person =
VAR CurrentRank = [Rank]
VAR CurrentSum = [Sum]
VAR NextPerson =
    FILTER ( ALLSELECTED ( 'Sales people' ); [Rank] = CurrentRank - 1 )
VAR NextPerson_Sum =
    MINX ( NextPerson; [Sum] )
RETURN
    IF ( NOT ISBLANK ( NextPerson_Sum ); CurrentSum - NextPerson_Sum )

This formula basically filters Sales People to the current rank minus 1, and evaluates Sum for that sales persion (using MINX in case of tied ranks for the next person).

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
Anonymous
Not applicable

It works like a charm! Thanks!

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.