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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Powerbi_User10
Regular Visitor

Top and top -1 values of list dynamically

Hello all,

 

I have a list of persons that have a score and a date of that score. Now I want to create a table in powerbi desktop with a bunch of things including their latest score and the score they have gotten before that dynamically.

 

I have this sample set:

Maya9/21/20225.4
Robbert9/20/20225
Vince9/20/20223.4
Vince3/12/20213.6
Vince6/5/20223.7
Robbert9/12/20222.9
Robbert5/5/20215.6
Lisa6/12/20229.9
Vince7/12/202219.2
Lisa8/20/20222.1

 

The result i would want to be like this:

MayaDepartment 1Address5.4NULL/EMPTY/0
RobbertDepartment 2Address52.9
VinceDepartment 2Address19.23.4
LisaDepartment 3Address2.19.9

 

I've looked into ranking etc, but i can't quite figure out how to do it in this specific context also because I want to put it in a table with other info.
When new data is added in the sample set i'd like it to automatically still pick the " top" and " top -1" value in the table.

 

If any more info is req let me know!

Thx!

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

Use these measures:

 

Score on last date =
VAR _LastDate =
    CALCULATE ( MAX ( fTable[Date] ), ALLEXCEPT ( fTable, fTable[Employee] ) )
RETURN
    CALCULATE (
        SUM ( fTable[Score] ),
        FILTER ( ALLEXCEPT ( fTable, fTable[Employee] ), fTable[Date] = _LastDate )
    )
Score on last date -1 =
VAR _LastDate =
    CALCULATE ( MAX ( fTable[Date] ), ALLEXCEPT ( fTable, fTable[Employee] ) )
VAR _PrevDate =
    CALCULATE (
        MAX ( fTable[Date] ),
        FILTER ( ALLEXCEPT ( fTable, fTable[Employee] ), fTable[Date] < _LastDate )
    )
RETURN
    CALCULATE (
        SUM ( fTable[Score] ),
        FILTER ( ALLEXCEPT ( fTable, fTable[Employee] ), fTable[Date] = _PrevDate )
    )

 

result.png

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

3 REPLIES 3
PaulDBrown
Community Champion
Community Champion

Use these measures:

 

Score on last date =
VAR _LastDate =
    CALCULATE ( MAX ( fTable[Date] ), ALLEXCEPT ( fTable, fTable[Employee] ) )
RETURN
    CALCULATE (
        SUM ( fTable[Score] ),
        FILTER ( ALLEXCEPT ( fTable, fTable[Employee] ), fTable[Date] = _LastDate )
    )
Score on last date -1 =
VAR _LastDate =
    CALCULATE ( MAX ( fTable[Date] ), ALLEXCEPT ( fTable, fTable[Employee] ) )
VAR _PrevDate =
    CALCULATE (
        MAX ( fTable[Date] ),
        FILTER ( ALLEXCEPT ( fTable, fTable[Employee] ), fTable[Date] < _LastDate )
    )
RETURN
    CALCULATE (
        SUM ( fTable[Score] ),
        FILTER ( ALLEXCEPT ( fTable, fTable[Employee] ), fTable[Date] = _PrevDate )
    )

 

result.png

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






AUDISU
Resolver III
Resolver III

@Powerbi_User10 

Hi,

There is no Depatment and Address in your sample table. How did you get that?

Do you have that data in same table?

Thanks

Hey, the department etc is just an example of other info in my table. the measure is only about the last scores that i want to " append" to my existing table in powerbi. The data model is set up so there is a relationship between an employee and a score so it can get a score per employee. But i want the last and second to last score per employee based on the lastest date of the score if that makes sense.

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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