Forum Discussion

ngct1112's avatar
ngct1112
Icon for Post Patron rankPost Patron
5 years ago
Solved

Measure - How to Rank a column by items

Hi all,

I am trying to summarize a table by ranking the cost.

Desired outcome:

-Only rank with the same "ID"

-The summarize table which only contains "Rank 1" or "Rank 2"

 

Here is what I am trying but NOT success:

 

 

 

Rank=RANKX(Filter(ALLSELECTED('Table'),'Table'[ID]='Table'[ID],CALCULATE(SUM('Table'[Cost])))

 

 

 

From

IDNamecostRank
1A102
1B81
2A51
2B82
3A21
3B42
4A62
4B51

 

Desired Outcome:

IDNamecostRank
1B81
2A51
3A21
4B51

 

Appreciate if any help!

  • Hi, ngct1112 

     

    It’s my pleasure to answer for you.

    According to your description,I think you can create a measure, then use it in filter pane.

    Like this:

    Rank =
    RANKX (
        FILTER ( ALL ( 'Table' ), 'Table'[ID] = SELECTEDVALUE ( 'Table'[ID] ) ),
        CALCULATE ( SUM ( 'Table'[Cost] ) ),
        ,
        1
    )

    If it doesn’t solve your problem, please feel free to ask me.

     

    Best Regards

    Janey Guo

     

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

6 Replies

  • Here is a version that uses a Calculated Column  (not a Measure!)

     

    Rank = 
    var tid = 'Table'[ID]
    return Rankx(filter('Table','Table'[ID]=tid),'Table'[cost])
  • Thanks lbendlin , However, the calculated column cannot be apply to the Slicer.
    Is there any way you could think of for the measure? Great thanks with your help anyways

  • Please explain what you mean by "calculated column cannot be used in a slicer".

  • lbendlin I am trying to put a slicer for column "Name", and the ultimate is to find out the ranking for selected value of this Slicer.
    If calculated in "Add column", the result will not be ranked for the designated filtered items.

  • v-janeyg-msft's avatar
    v-janeyg-msft
    Icon for Community Support rankCommunity Support

    Hi, ngct1112 

     

    It’s my pleasure to answer for you.

    According to your description,I think you can create a measure, then use it in filter pane.

    Like this:

    Rank =
    RANKX (
        FILTER ( ALL ( 'Table' ), 'Table'[ID] = SELECTEDVALUE ( 'Table'[ID] ) ),
        CALCULATE ( SUM ( 'Table'[Cost] ) ),
        ,
        1
    )

    If it doesn’t solve your problem, please feel free to ask me.

     

    Best Regards

    Janey Guo

     

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