Forum Discussion

darshaningale's avatar
darshaningale
Resolver II
3 years ago
Solved

Rank based on category column

I have three columns Category , subcategory and Amount column. 
I am adding category , subcategory and sum of amount column in table. I want to calculate rank (sum of amount column) based on only Category and should not change by addition of subcategory.

  • v-jingzhang's avatar
    v-jingzhang
    3 years ago

    Hi darshaningale 

     

    Sorry I think this measure should be helpful.

    Rank = RANKX(ALLSELECTED('Table'[SubCat]),CALCULATE(SUM('Table'[Amount])))

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.

9 Replies

  • v-jingzhang's avatar
    v-jingzhang
    Community Support

    Hi darshaningale 

     

    You can create a measure with below formula, then add it to the same table visual. This measure ranks Category based on Sum of Amount descendingly. 

    Rank = RANKX(ALLSELECTED('Table'),CALCULATE(SUM('Table'[Amount]),ALLEXCEPT('Table','Table'[Category])),,DESC,Dense)

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.

    • darshaningale's avatar
      darshaningale
      Resolver II

      For the data mentioned by you, the rank should be 1 for 100 , 2 for 30 ... Then again it should be 1 for 40 and 2 for 23. Then again it should be 1 for 93 and 2 for 80

      • v-jingzhang's avatar
        v-jingzhang
        Community Support

        Hi darshaningale 

         

        You can use this measure

        Rank = RANKX(ALLEXCEPT('Table','Table'[Category]),CALCULATE(SUM('Table'[Amount])),,DESC,Dense)

        Best Regards,
        Community Support Team _ Jing
        If this post helps, please Accept it as Solution to help other members find it.