Forum Discussion

StefanM's avatar
StefanM
Icon for Helper II rankHelper II
6 years ago
Solved

Top N per date in a chart

Hello PBI community!

I'm trying to show the most common categories based on a charts drilled down selection. So if it's drilled all the way down to individual dates, then the chart displays the top 5 categories per date. But if it's higher, on say week or month, then it shows the top 5 for each week or month instead. 

 

 Date/Week/Month 1 has a different top 5 from Date/Week/Month 2. But the problem I'm encountering is in filtering by Top N which filters to only show me the Top 5 for the entire range, so only 5 categories show in total, even though they are not the top 5 for those specific ranges. 

To give an idea of what I'm aiming for here, here's an image of an example table showing off the raw data (left) to the final table (right) using some common sense working out. 

 

From Raw Data to Final Table

 

In actuality, there are potentially 100s of Categories and the list is ever-growing. So it needs to be something dynamic. I've been wrecking my head on this for a few days and can't figure it out.

Any wizards out there who can help?

  • Anonymous's avatar
    Anonymous
    6 years ago

    I think you are looking for this:

     

    Calculated column: 

     

    Rank =
    RANKX(FILTER('Table','Table'[Date]=EARLIER('Table'[Date])),'Table'[Quantity])
     
    At least that took me from your table 2 to table 3 🙂

4 Replies

  • I've made the middle table in the image, now I just need to rank them to prevent the items beyond the top 3 from appearing. 
    How can I go about that? I've tried so many measures, but nothing is working.  

    Image below for example:

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      I think you are looking for this:

       

      Calculated column: 

       

      Rank =
      RANKX(FILTER('Table','Table'[Date]=EARLIER('Table'[Date])),'Table'[Quantity])
       
      At least that took me from your table 2 to table 3 🙂
      • StefanM's avatar
        StefanM
        Icon for Helper II rankHelper II

        Ohh, this is nice! Works very well. Every category available on each date is now ranked. 

        Now I've a new problem, the ranking doesn't stay true to the date selection on the chart. 

         

        As seen in the above image, the bottom left chart is filtered down to Day, in which the top 3 is shown as expected. But in the top chart that's drilled up to Monthly Data, the top 3 for each day is shown on that month, rather than the top 3 per month... 

        I'm thinking that I'm perhaps going about this wrong S: any ideas?