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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Trying to create a measure that return top 5 of another measure, but all values are returned

Hi All,

 

 

I hope someone can help me solve my issue. 

 

I'm trying to find the top 5 values of a variable stored inside a measure using the TOPN function - however all values are returned. 

 

The variable consists of a if-statement and the ALLSELECTED function (not sure if this messes up the TOPN-func?)

 

Here's my measure that I've built:

 

Measure = 

VAR rank1 = 

IF (
        NOT ( ISBLANK ( 'Salesforce'[Brutto sales] ) ) && Salesforce[Total sales]>=85000 && NOT ( 'Salesforce'[Total sales]=0 ) && [no ready]>=30,
        
        RANKX (
            FILTER ( ALLSELECTED ( Agent[Name]), NOT ( ISBLANK ( 'Salesforce'[Brutto sales] ) ) ),
            'Salesforce'[Brutto sales],,DESC
        )
    
+


        RANKX (
            FILTER ( ALLSELECTED ( Agent[Name] ), NOT ( ISBLANK ( 'Salesforce'[Total sales] ) ) ),
            'Salesforce'[Total sales],,DESC
        )+[RANDOM]
    
,



        RANKX (
            FILTER ( ALLSELECTED ( Agent[Name] ), NOT ( ISBLANK ( 'Salesforce'[Brutto sales] ) ) ),
            'Salesforce'[Brutto sales],,DESC
        )
    
+

        RANKX (
            FILTER ( ALLSELECTED ( Agent[Name] ), NOT ( ISBLANK ( 'Salesforce'[Total sales] ) ) ),
            'Salesforce'[Total sales],,DESC
        )+1000+[RANDOM]
)

return


CALCULATE(rank1,KEEPFILTERS(
TOPN(5,ALL(Agent[Name]),rank1,DESC)))

 

 

As you see on the picture below - my measure returns all values instead of only the top 5:

NicoM96_0-1677171985407.png

 

Can someone help me solve this issue, so all other values (instead of the top 5) i blank?

 

Best,

 

NicoM96

 

 

 

 

3 REPLIES 3
Padycosmos
Solution Sage
Solution Sage

Greg_Deckler
Community Champion
Community Champion

@Anonymous Try using Top N filtering in Filter pane for Agent based on Measure?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi Greg,

 

Thanks for a quick response on my question.

 

However the TOPN function in the filter pane is not a suitable solution for my issue as I want to manipulate the measure further to return middle values e.g. top 6-10 etc.

 

Do you know how I can correct the measure so I don't have to use the filter pane?

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors