Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

categories in different Top n

we have following table, for different category different top n are requirent, for ex: the result should look like below. shoes need top 3, books top 3, polish top2, Accesorries top1. Kindly help with solution

 

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi  Anonymous ,

    Here are the steps you can follow:

    1. Create calculated column.

    rank = RANKX(FILTER(ALL('Table'),'Table'[Category]=EARLIER('Table'[Category])),[sales])

    2. Create measure.

    Flag =
    SWITCH(
        TRUE(),
        MAX('Table'[Category])="shoes",IF(MAX('Table'[rank])<=3,1,0),
        MAX('Table'[Category])="polish",IF(MAX('Table'[rank])<=2,1,0),
        MAX('Table'[Category])="book",IF(MAX('Table'[rank])<=3,1,0),
        MAX('Table'[Category])="Accessorie",IF(MAX('Table'[rank])>=3,1,0))

    3. Place [Flag]in Filters, set is=1, apply filter.

    4. Result:

     

    Best Regards,

    Liu Yang

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

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  Anonymous ,

    Here are the steps you can follow:

    1. Create calculated column.

    rank = RANKX(FILTER(ALL('Table'),'Table'[Category]=EARLIER('Table'[Category])),[sales])

    2. Create measure.

    Flag =
    SWITCH(
        TRUE(),
        MAX('Table'[Category])="shoes",IF(MAX('Table'[rank])<=3,1,0),
        MAX('Table'[Category])="polish",IF(MAX('Table'[rank])<=2,1,0),
        MAX('Table'[Category])="book",IF(MAX('Table'[rank])<=3,1,0),
        MAX('Table'[Category])="Accessorie",IF(MAX('Table'[rank])>=3,1,0))

    3. Place [Flag]in Filters, set is=1, apply filter.

    4. Result:

     

    Best Regards,

    Liu Yang

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