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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
rajatagarwal93
New Member

Create a Rank column/field based on a filter.

Hi 

 

I am trying to create a column named "Rank" in a table (see example below). I am okay with either DAX or M query. I want to Partition by Visit ID, and Order by Join Time in ascending order. It should only rank when the "Role" is Doctor else rank 0. Also, if its the same participant ID in the same visit ID then the rank should be same. For ex. Participant "a" is present twice in Visit ID "1" so the doctor gets the rank 1 in both the rows.

 

Join timeVisit IDParticipant IDRoleRank
01/02/20241aDoctor1
02/02/20241bPatient0
03/02/20241aDoctor1
04/02/20241zDoctor2
05/02/20242cDoctor1
06/02/20242dPatient0
07/02/20243aDoctor1
08/02/20244cPatient0
09/02/20245aDoctor1
10/02/20245eDoctor2
11/02/20245fPatient0

 

 

 

Any help would be greatly appreciated.

Thanks

 

1 ACCEPTED SOLUTION
govindarajan_d
Solution Supplier
Solution Supplier

Hi @rajatagarwal93 ,

 

Can you try this measure: 

The data is summarized to find the minimum date for each participant id within a Visit ID

Then the min date is used to order by in the RANK DAX function to calculate the ranking. 

 

 

 

 

RankDoctor =
VAR __Summarized =
    SUMMARIZE (
        FILTER ( ALL ( RankTable ), RankTable[Role] = "Doctor" ),
        RankTable[Visit ID],
        RankTable[Participant ID],
        "MinDate", MIN ( RankTable[Join time] )
    )
VAR __Rank =
    RANK (
        DENSE,
        __Summarized,
        ORDERBY ( [MinDate], ASC ),
        DEFAULT,
        PARTITIONBY ( RankTable[Visit ID] )
    )
RETURN
    IF ( SELECTEDVALUE ( RankTable[Role] ) = "Doctor", __Rank, 0 )

 

 

 

 

Rank column is from your question. I had it to refer if my measure was correct. 
RankDoctor is the measure from above formula (the last column) and it matches with the output you had given. 

govindarajan_d_0-1708139108845.png

 

 

 

View solution in original post

2 REPLIES 2
govindarajan_d
Solution Supplier
Solution Supplier

Hi @rajatagarwal93 ,

 

Can you try this measure: 

The data is summarized to find the minimum date for each participant id within a Visit ID

Then the min date is used to order by in the RANK DAX function to calculate the ranking. 

 

 

 

 

RankDoctor =
VAR __Summarized =
    SUMMARIZE (
        FILTER ( ALL ( RankTable ), RankTable[Role] = "Doctor" ),
        RankTable[Visit ID],
        RankTable[Participant ID],
        "MinDate", MIN ( RankTable[Join time] )
    )
VAR __Rank =
    RANK (
        DENSE,
        __Summarized,
        ORDERBY ( [MinDate], ASC ),
        DEFAULT,
        PARTITIONBY ( RankTable[Visit ID] )
    )
RETURN
    IF ( SELECTEDVALUE ( RankTable[Role] ) = "Doctor", __Rank, 0 )

 

 

 

 

Rank column is from your question. I had it to refer if my measure was correct. 
RankDoctor is the measure from above formula (the last column) and it matches with the output you had given. 

govindarajan_d_0-1708139108845.png

 

 

 

It worked. Thanks for such a quick response.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.