cancel
Showing results for
Did you mean:  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. 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. Any ideas?

1 ACCEPTED SOLUTION  Super User

Hi @Ville

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

My Blog
2 REPLIES 2  Super User

Hi @Ville

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

My Blog  Helper I

It works like a charm! Thanks! Announcements #### The Power BI Community Show

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