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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Get Second and Third values in a Rank

Hi,

I have a table that contains data about logins by employees. An employee can have multiple rows per day.

JMerino_0-1646672345341.png

 

My report is filtering by day and I need to show in my report 3 cards. The first one should show the name of the employee with more logins, the second one the second employee with more logins, and in the third, the third employee with more logins.

I have been trying with ranks, but I'm not able to get a good result.

For instance, if I select day 1:

Card 1 should show C (9)

Card 2 should show A (7)

Card 3 should show D (2)

 

For instance, if I select day 4:

Card 1 should show D

Card 2 should show B

Card 3 should show A

 

Thanks in advance for your help.

 

 

 

 

 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture1.png

 

Ranking: =
RANKX ( ALL ( Employee[Employee] ), CALCULATE ( SUM ( Data[Logins] ) ),, DESC )

 

Rank one: = 
VAR ranktable =
    FILTER (
        ADDCOLUMNS(
            VALUES(Employee[Employee]),
            "@rank", [Ranking:]
        ),
        [@rank] = 1
    )
RETURN
    MAXX ( ranktable, Employee[Employee] ) & " ("
        & CALCULATE (
            SUM ( Data[Logins] ),
            Employee[Employee] = MAXX ( ranktable, Employee[Employee] )
        ) & ")"

 

Rank two: = 
VAR ranktable =
    FILTER (
        ADDCOLUMNS(
            VALUES(Employee[Employee]),
            "@rank", [Ranking:]
        ),
        [@rank] = 2
    )
RETURN
    MAXX ( ranktable, Employee[Employee] ) & " ("
        & CALCULATE (
            SUM ( Data[Logins] ),
            Employee[Employee] = MAXX ( ranktable, Employee[Employee] )
        ) & ")"

 

Rank three: = 
VAR ranktable =
    FILTER (
        ADDCOLUMNS(
            VALUES(Employee[Employee]),
            "@rank", [Ranking:]
        ),
        [@rank] = 3
    )
RETURN
    MAXX ( ranktable, Employee[Employee] ) & " ("
        & CALCULATE (
            SUM ( Data[Logins] ),
            Employee[Employee] = MAXX ( ranktable, Employee[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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Picture1.png

 

Ranking: =
RANKX ( ALL ( Employee[Employee] ), CALCULATE ( SUM ( Data[Logins] ) ),, DESC )

 

Rank one: = 
VAR ranktable =
    FILTER (
        ADDCOLUMNS(
            VALUES(Employee[Employee]),
            "@rank", [Ranking:]
        ),
        [@rank] = 1
    )
RETURN
    MAXX ( ranktable, Employee[Employee] ) & " ("
        & CALCULATE (
            SUM ( Data[Logins] ),
            Employee[Employee] = MAXX ( ranktable, Employee[Employee] )
        ) & ")"

 

Rank two: = 
VAR ranktable =
    FILTER (
        ADDCOLUMNS(
            VALUES(Employee[Employee]),
            "@rank", [Ranking:]
        ),
        [@rank] = 2
    )
RETURN
    MAXX ( ranktable, Employee[Employee] ) & " ("
        & CALCULATE (
            SUM ( Data[Logins] ),
            Employee[Employee] = MAXX ( ranktable, Employee[Employee] )
        ) & ")"

 

Rank three: = 
VAR ranktable =
    FILTER (
        ADDCOLUMNS(
            VALUES(Employee[Employee]),
            "@rank", [Ranking:]
        ),
        [@rank] = 3
    )
RETURN
    MAXX ( ranktable, Employee[Employee] ) & " ("
        & CALCULATE (
            SUM ( Data[Logins] ),
            Employee[Employee] = MAXX ( ranktable, Employee[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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

I was struggling with the same issue, thanks @Jihwan_Kim . Your solution worked like a baby. But I managed to make it a single measure instead of three with below code. I had to create a table named "Rank" to acheive it though. "Rank" table had a single column "Ranks" with values from 1 to 3.

 

Rank one: = 
VAR ranktable =
    FILTER (
        ADDCOLUMNS(
            VALUES(Employee[Employee]),
            "@rank", [Ranking:]
        ),
        [@rank] = SELECTEDVALUE(Rank[Ranks])
    )
RETURN
    MAXX ( ranktable, Employee[Employee] ) & " ("
        & CALCULATE (
            SUM ( Data[Logins] ),
            Employee[Employee] = MAXX ( ranktable, Employee[Employee] )
        ) & ")"

  

Anonymous
Not applicable

It worked, thanks a lot!!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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