Forum Discussion

Muratik55's avatar
Muratik55
Helper I
3 years ago
Solved

Top 5 + Others

Hello everyone,

In my table i have two columns that i need to work on > Client, Pieces

Based on those two columns i would like to get top 5 + others data.
So top 5 client name and the rest will be sum up as "Others"

I used below query but didn't return 5+ others. it just returns everything..


TopN+Others =
Var RankClientByStop = RANKX(ALL('Scheduled'),[Pieces],,DESC)
return
IF(RankClientByStop <= 5, [Client], "Others")

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Muratik55 ,

     

    Your [TopN+Others] is a calcualted column, right?

    And please tell me if [Client - Copy.1.1] and [Pieces] are measures or columns.

    For now, according to my guess, your [Pieces] and [TopN+Others] are measures.

    The reason for the issue is that the same client in your table may have multiple rows, so think as follows:

    Client A: 3 rows

    Client B: 2 rows

    And I tried to reproduced your issue.

    You can modify the measure to get the right ranking numbers. Below is the measure in the screenshot.

    Final result:

     

    Measure = 
    VAR _TABLE1= SUMMARIZE(ALL('Scheduled'),[Client],"A",[Pieces measure])
    VAR _TABLE2=ADDCOLUMNS(_TABLE1,"RANKX",RANKX(_TABLE1,[A],,DESC))
    VAR _RANK=SUMX(FILTER(_TABLE2,[Client]=MAX('Scheduled'[Client])),[RANKX]
    )
    RETURN IF(_RANK <= 5, MAX('Scheduled'[Client]), "Others")
    

     

    If you still have questions, please let me know how your data differs from my sample data.

    Measures and calculated columns are different.

     

     

                                                                                                                                                             

    Best Regards,

    Stephen Tao

     

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

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Muratik55 ,

     

    It seems work fine on my testing data.

    And removing ALL function is also OK.

    Please tell me more about the issue. If possible, please provide me with some sample data and expected results. Take care to protect data privacy.

     

                                                                                                                                                             

    Best Regards,

    Stephen Tao

     

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

     

    • Muratik55's avatar
      Muratik55
      Helper I

      it is just taking one client and dumping rest of them in "Others". it was also assigning 1 to every row. RankX seems doesn't working.

       

      • Muratik55's avatar
        Muratik55
        Helper I
        TopN+Others =
         RANKX(ALL('Orders Scheduled'[Client - Copy.1.1]),[Pieces],,DESC)

        RankX doesn't work properly