Forum Discussion

WinterMist's avatar
WinterMist
Impactful Individual
3 years ago
Solved

RANKX - Unable to RANK Rows For Each Category

Hello Community -    Frustrated with myself that I can't figure this out. I've read about 10-15 related pages on forums, SQLBI etc., but still failing. Seems like this should be incredibly easy. ...
  • v-yueyunzh-msft's avatar
    3 years ago

    Hi , WinterMist 

    Thanks for your sample data and end result first!
    According to your description, you want to rank by the [Unique ID] group by the [City].

    Here are the steps you can refer to :
    (1)If you want to create a calculated column in the table , you can use this dax:

    Column = RANKX( FILTER('Table','Table'[City] = EARLIER('Table'[City])) , 'Table'[Unique ID] ,,ASC ,Dense)

    (2)If you want to create a measure , you can use this dax:

    Measure = RANKX(CALCULATETABLE( VALUES('Table'[Unique ID]), ALLEXCEPT('Table','Table'[City])) , CALCULATE( SUM('Table'[Unique ID]),ALLEXCEPT('Table','Table'[Unique ID])) ,,ASC,Dense)
     

     

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly