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

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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


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
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.