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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

Adding additional criteria to RANKX

I have a column which ranks by student code and date change using the following:

 

Rank = RANKX( FILTER( 'Table', [StudentID] = EARLIER( [StudentID] )), [ChangeDate] , , ASC, DENSE)
 
which gives me the following table:
StudentIDChangeDateAcademicYearRank
Student101/10/20202019/201
Student102/10/20202019/202
Student109/10/20202019/203
Student202/10/20202019/201
Student211/10/20202019/202
Student212/10/20202019/203
Student213/10/20202020/214
Student307/10/20202019/201
Student311/10/20202019/202
Student316/10/20202020/213
Student407/10/20202019/201
Student408/10/20202019/202

 

What I would like is to add additional criteria in order to restart the ranking wherever there is a change of AcademicYear for each student, so the table would look as follows (changes highlighted in red):

StudentIDChangeDateAcademicYearRankNEWRank
Student101/10/20202019/2011
Student102/10/20202019/2022
Student109/10/20202019/2033
Student202/10/20202019/2011
Student211/10/20202019/2022
Student212/10/20202019/2033
Student213/10/20202020/2141
Student307/10/20202019/2011
Student311/10/20202019/2022
Student316/10/20202020/2131
Student407/10/20202019/2011
Student408/10/20202019/2022
 
Any suggestions as to how to achieve this please?  Many thanks
1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @Anonymous 

Rank V2 =
RANKX (
    FILTER (
        Table1,
        Table1[StudentID] = EARLIER ( Table1[StudentID] )
            && Table1[AcademicYear] = EARLIER ( Table1[AcademicYear] )
    ),
    Table1[ChangeDate],
    ,
    ASC,
    DENSE
)

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

3 REPLIES 3
edhans
Community Champion
Community Champion

The following measure will do it @Anonymous I believe.

 

 

New Rank =
VAR varStudentID =
    MAX( 'Table'[StudentID] )
VAR varAcademicYear =
    MAX( 'Table'[AcademicYear] )
VAR Result =
    RANKX(
        FILTER(
            ALL( 'Table' ),
            'Table'[StudentID] = varStudentID
                && 'Table'[AcademicYear] = varAcademicYear
        ),
        CALCULATE(
            SELECTEDVALUE( 'Table'[ChangeDate] )
        ),
        ,
        ASC,
        DENSE
    )
RETURN
    Result

 

 

edhans_0-1609951464817.png

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
AlB
Community Champion
Community Champion

Hi @Anonymous 

Rank V2 =
RANKX (
    FILTER (
        Table1,
        Table1[StudentID] = EARLIER ( Table1[StudentID] )
            && Table1[AcademicYear] = EARLIER ( Table1[AcademicYear] )
    ),
    Table1[ChangeDate],
    ,
    ASC,
    DENSE
)

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

parry2k
Super User
Super User

@Anonymous try this

 

Rank  = RANKX( FILTER( 'Rank', 'Rank'[StudentID] = EARLIER( 'Rank'[StudentID] ) && 'Rank'[AcademicYear] = EARLIER('Rank'[AcademicYear])), 'Rank'[ChangeDate] , , ASC, DENSE)
 

 

Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.