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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
datawiz23
Frequent Visitor

Rank DAX problem in Power BI

This problem has been sending me potty.

 

I know it should be relatively be simple but I can't crack it, originally I tried to solve it using RANKX but I couldn't get it to work so I tried RANK and still no joy, could someone help?

 

The semantic model I'm using is for the Times University Rankings, all years

 

I have a ranking value for each university and in it's simplest form I just want to rank a university's position within it's country.

 

A really simple example is in 2011, there were two universities in Austria in the Times university Top 200:

University of Vienna - ranked 195 overall &

University of Innsbruck - ranked 187 overall

 

All I want to do is to introduce a DAX measure that ranks the order at Year, Country, University level:

so Innsburck would be 1 and Vienna 2

 

Please could someone help and save me from insanity?

 

I thought it might look something like this but with extra fields, no matter what I try I just can't get it to work, thanks Mark:

 

Rank University by Country =

RANK (

DENSE,

ALLSELECTED ( 'fact' [university]),

ORDERBY ( [ times ranking], DESC)

1 ACCEPTED SOLUTION

@datawiz23 

Create the following measure to rank by Rating under each Country:

Uni Rank = 
VAR __T = ALLSELECTED( 'Table' )
VAR __Result = 
    RANK( 
         DENSE,
        __T ,
        ORDERBY('Table'[World Rank in Year],ASC),,
        PARTITIONBY( 'Table'[country])
    )
RETURN
    __Result

Fowmy_0-1701890462625.png

File attached below

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

4 REPLIES 4
datawiz23
Frequent Visitor

sorry for the delay @Fowmy 

here is some data from the model

yearcountryUniversityWorld Rank in Year
2023AlbaniaPolytechnic University of Tirana100036.8
2019AlgeriaBadji Mokhtar University – Annaba1023
2022AlgeriaBadji Mokhtar University – Annaba1234
2023AlgeriaBadji Mokhtar University – Annaba1528
2021AlgeriaBlida 1 University1066
2022AlgeriaBlida 1 University1251
2023AlgeriaBlida 1 University1541
2023AlgeriaÉcole Nationale Polytechnique100013.7
2023AlgeriaÉcole Polytechnique d’Architecture et d’Urbanisme100013.8
2019AlgeriaFerhat Abbas Sétif University 1871
2020AlgeriaFerhat Abbas Sétif University 1652
2021AlgeriaFerhat Abbas Sétif University 1527
2022AlgeriaFerhat Abbas Sétif University 1536
2023AlgeriaFerhat Abbas Sétif University 1426

kind regards,

Mark

@datawiz23 

Create the following measure to rank by Rating under each Country:

Uni Rank = 
VAR __T = ALLSELECTED( 'Table' )
VAR __Result = 
    RANK( 
         DENSE,
        __T ,
        ORDERBY('Table'[World Rank in Year],ASC),,
        PARTITIONBY( 'Table'[country])
    )
RETURN
    __Result

Fowmy_0-1701890462625.png

File attached below

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Thanks @Fowmy it worked a treat, the key was PARTITION I think.  Kind regards, Mark

Fowmy
Super User
Super User

@datawiz23 

Please share a sample of your data. you can paste it here from excel ot csv

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors