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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
MarceDF
Frequent Visitor

Measure to calculate TOP 1

Hi everyone, I have this data:

Group AgeQty
25 - 341992
19 - 241726
45 - 541316
35 - 44948
63 - 72925
55 - 62803
'+ 72725
7 to 14497
15 - 18444
4 to 6149
0 - 386

 

The QTY is a measure that is called [Active Members]

I created this measure that give me the Age Group with most Active Members:

Which age is the most active (is working) give me the 25 - 34 group=
CALCULATE (
    MAX ( 'dimAgeGroup'[Group Age] ),
    TOPN ( 1, ALL ( 'dimAgeGroup'[Group Age] ), [Active Members], DESC ),
    VALUES ( 'dimAgeGroup'[Group Age] )
)
   But when I want to make the opposite (does not work) give me the 72+ group:
Which age is the less active =
CALCULATE (
    MIN ( 'dimAgeGroup'[Group Age] ),
    TOPN ( 1, ALL ( 'dimAgeGroup'[Group Age] ), [Active Members], ASC ),
    VALUES ( 'dimAgeGroup'[Group Age] )
)

   What I am doing wrong?
2 REPLIES 2
ValtteriN
Super User
Super User

Hi,

Top 1 is actually returning a list like this in your dax:

ValtteriN_0-1684825076085.png

 

Instead of using Top1 try using RANKX

Top 1 with rank =
CALCULATE(MAX(dimAgeGroup[Group Age]),
FILTER(dimAgeGroup,RANKX(ALLSELECTED(dimAgeGroup),[qty sum])=1))

RANKX also has the option for ASC/DESC and you can use it like this:

Top 1 with rank =
CALCULATE(MAX(dimAgeGroup[Group Age]),
FILTER(dimAgeGroup,RANKX(ALLSELECTED(dimAgeGroup),[qty sum],,ASC)=1))


Here is an example with ASC:
ValtteriN_1-1684825166853.png

 

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/






Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi,

Thank you for the explanation. I tried to translate to the report and only for the biggest qty it works, for the less, don't. I changed the MAX to MIN and the ASC to DESC and also played with the combinations but didn't succed.

Which age is the less active =

CALCULATE ( MIN ( 'dimAgeGroup'[Group] ),
    FILTER ( 'dimAgeGroup' ,
        RANKX ( ALLSELECTED ( 'dimAgeGroup' )
            , [Active Members] , , DESC
        ) = 1
    )
)
   If I use like this I receive 72+
 
Which age is the less active =

CALCULATE ( MIN ( 'dimAgeGroup'[קבוצה] ),
    FILTER ( 'dimAgeGroup' ,
        RANKX ( ALLSELECTED ( 'dimAgeGroup' )
            , [Active Members History] , , ASC
        ) = 1
    )
)
   

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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