cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ville
Helper I
Helper I

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 @Ville

 

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!

My Blog
Connect on Twitter
Connect on LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi @Ville

 

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!

My Blog
Connect on Twitter
Connect on LinkedIn

It works like a charm! Thanks!

Helpful resources

Announcements
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors