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
Craines
Helper II
Helper II

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
Super User
Super User

Hi @Craines 

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
Super User
Super User

The following measure will do it @Craines 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
Super User
Super User

Hi @Craines 

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

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