Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mateoc15
Advocate I
Advocate I

Top N from current month

I'm using the Top N filter for top 10 in a ribbon chart.  It's picking up the top 10 values numerically across the three months I've filtered, but what I'm looking for is to find the top 10 for the most recent month in the filter (June below) and then show those 10 going back to the start date (April below).  Hope that makes sense.  Is there a way to do this natively, or does it require filtering on a custom measure?  If so, what might that measure look like with a field [Date] and [Category]?

mateoc15_0-1596027139847.png

 

 

4 REPLIES 4
v-yiruan-msft
Community Support
Community Support

Hi @mateoc15 ,

Please check whether the below screen shot is what you want:

1. Create a measure

Top 10 for most recent month = 
VAR _rank =
    RANKX (
        ALLEXCEPT ( 'Ribbon chart', 'Ribbon chart'[Date] ),
        CALCULATE ( SUM ( 'Ribbon chart'[Rate] ) ),
        ,
        DESC,
        DENSE
    )
RETURN
    IF ( _rank <= 10, MAX ( 'Ribbon chart'[Rate] ), BLANK () )

2. Apply the new created measure onto ribbon chart

Top N from current month.JPG

If the above ones is not what you want, please provide your expected result and explain more details with examples. Thank you. 

Best Regards

Rena

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

Maybe I'm just not using your work correctly, but I don't think it's what I'm looking for.

 

To maybe state the desired outcome differently, I want the top 10 for June, then the ribbon (or whatever viz) just show me what those same 10 looked like in April and May.  Those 10 might not be top 10 across the 3 month period, but I want to know details about the ones that are currently (if June is current month) top 10.

I took a shot at a DAX calculation based on what you provided but no luck.

Hi @mateoc15 ,

You can create 3 measures as below:

Rank = 
var _mdate=CALCULATE(MAX('Table'[Date]),ALL('Table'))
VAR _rank =
    RANKX (
        ALLEXCEPT ( 'Table', 'Table'[Date] ),
        CALCULATE ( SUM ( 'Table'[Rate] ) ),
        ,
        DESC,
        DENSE
    )
RETURN
_rank
Top 3 Category = 
var _mdate=CALCULATE(MAX('Table'[Date]),ALL('Table')) 
VAR _tempTab=  CALCULATETABLE(DISTINCT('Table'[Category]),FILTER(ALL('Table'),[Rank]<=3&&'Table'[Date]=_mdate))
var _category=CALCULATE(CONCATENATEX(_tempTab,[Category],","),ALL('Table')) 
return _category
Measure = 
VAR mymeasure=SUBSTITUTE([Top 3 Category],",","")
VAR Mylen=len(mymeasure)
VAR mytable=ADDCOLUMNS(GENERATESERIES(1,mylen),"mylist",(Mid(mymeasure,[Value],1)))
VAR mylist=SELECTCOLUMNS(mytable,"list",[mylist])
RETURN
CALCULATE(SUM('Table'[Rate]),FILTER('Table','Table'[Date]=MAX('Table'[Date])&&'Table'[Category] in mylist))

Top N_update.JPG

Best Regards

Rena

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

Hi @Anonymous , thank you for this DAX sytax. The only problem I am facing to do the same is that ,my categories are not letters, they are words and phrases sometimes. How do you address this? Thank you.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.