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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anna123456
Frequent Visitor

TopN with returns too much

Hello, 

 

When I use TopN for 2 it gives me more than 2 records back ... it gives me all the records that have one of the 2 maximum numbers. How can I restrict the output to 2? And if multiple values have the maximum number it should choose a random sample.... 

 

Example: 

A: 3
B: 7

C: 7
D : 7 

E: 4
-> Top 2 gives me C,D,B, E (because the 2 maximum numbers are 7 and 4)  but I just want C and D (or C and B ... does not matter, but just 2). 

 

Can you help me? 

 

~Anna 

 

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1679633140262.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1679633140262.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

WinterMist
Impactful Individual
Impactful Individual

@Anna123456 

 

First, put the Top 2 Numbers into a table VAR (which will return 3 rows of Number 7).

Second, get the Top 2 Letters from the table VAR in Step 1 above.

 

WinterMist_0-1679598897390.png

 

Regards,

Nathan

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.