Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Rankx producing incorrect order

Hello,

 

I am trying below calculated column in my dataset to return a rank to limit my bar chart 

 

Custom Col Cancellation Ranks =
Var RankByCancellation=
RANKX(
All(MyPT_Cancellations),
CALCULATE(
COUNT(MyPT_Cancellations[No. of Clients]),
ALLEXCEPT(MyPT_Cancellations,MyPT_Cancellations[Cancellation reason])
),
,
DESC,
Dense
)
Return
IF(RankByCancellation<=9,RankByCancellation,10)

Now, this works but I doubt it does sorting counts by descending order 

 

Can somebody please advise me urgently?

 
 
 
 

8 Replies

  • Anonymous , are you viewing it for Cancellation reason?

     

    Then try like

    Custom Col Cancellation Ranks =
    Var RankByCancellation=
    RANKX(
    All(MyPT_Cancellations[Cancellation reason]), // or use allselected in place of all
    CALCULATE(
    COUNT(MyPT_Cancellations[No. of Clients]),
    ALLEXCEPT(MyPT_Cancellations,MyPT_Cancellations[Cancellation reason])
    ),
    ,
    DESC,
    Dense
    )
    Return
    IF(RankByCancellation<=9,RankByCancellation,10)

     

    Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi amitchandak 

      Sorry, i tried Allselected but doesnt changed anything. Let me share table format and output 

      • amitchandak's avatar
        amitchandak
        Super User

        Anonymous , have tried with

        All(MyPT_Cancellations[Cancellation reason])

         

        Allselected(MyPT_Cancellations[Cancellation reason])

  • Anonymous's avatar
    Anonymous
    Not applicable

    Anonymous 

    For the first question, replace the allexcept to following:

     

    Custom Col Cancellation Ranks =
    Var RankByCancellation=
    RANKX(
    All(MyPT_Cancellations[Cancellation reason]), // or use allselected in place of all
    CALCULATE(
    COUNT(MyPT_Cancellations[No. of Clients]),
    Filter(Allselected(MyPT_Cancellations), MyPT_Cancellations[Cancellation reason]=MAX( MyPT_Cancellations[Cancellation reason])
    ),
    ,
    DESC,
    Dense
    )
    Return
    IF(RankByCancellation<=9,RankByCancellation,10)

     


    For more, please share a sample table or pbix(Not image),  that would make your current situation clear for us.

     


    Paul Zheng _ Community Support Team
    If this post helps, please Accept it as the solution to help the other members find it more quickly.