Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

TopN/RankX issues

I want to find Top 10 products. I want to check month wise sales of those top 10 product.
Top 10 products should be calculated dynamically I have to apply multiple filters on this(ex: location, category)

My ask is build the TopN visual level filter manually with help of DAX measures.

#PowerBI #Desktop #TopN # RankX #Filter

15 Replies

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

    Hi, Anonymous 

     

    Can you provide sample data for testing? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures or Excel. I look forward to your response.

     

    Best Regards,

    Community Support Team _Charlotte

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

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi v-zhangti 
      I could not share the data but can explain this in detail.

      Assume there is list of 20 products. I want to see top 5 products and total sales at month level.

      sharing you the scrrnshot below for reference of output i am expecting.

                       TOP5 Products
       Month Year 
      ProductsJan-23Feb-23Mar-23Apr-23Total
      A2010401080
      B25125020107
      C2011401081
      D23303030113
      E24501040124
      Total112113170110505

       

      This can be acheived easily by TOPN visual level filter but my requirement is to do it with DAX measures because I have to parametrize "N". 
      I have tried making it with TOPN and RANKX but when Month-Year column comes in picture it do not work correct.

      Hope this make problem clear.

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

        Hi, Anonymous 

         

        You can try the following methods.

        Rank = RANKX(ALL('Table'),CALCULATE(SUM('Table'[Sales]),ALLEXCEPT('Table','Table'[Products])),,DESC,Dense)
        Measure = IF([Rank]<=3,1,0)

        The Top 3 products are shown at this time.

         

        Best Regards,

        Community Support Team _Charlotte

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