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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
jeanL
Helper I
Helper I

RANKX with filter

I am trying to display only top 10 in the table and have been looking up to try using TOPN and RANKX.

But i have been having issue with rankx, with it displaying 1 rank across the table.

The table is expected to be filtered by three criteria, 

1. main_service

2. direction 

3. customer_segment

 

I have tried using adding columns and it gives me the ranks throughout the entire table. But i am looking for a dynamic ranking where it will be ranked as the filter is applied. 

rank = RANKX(ALLSELECTED(summary_table), [total_teus],,0)

 

 

rank is using new column with the above code, while rankings, i have been trying with code below. 

rankings = CALCULATE(
    RANKX(ALLSELECTED(summary_table[od_pairs]), SUM([total_teus]),,0))

 

 

 

snippet.PNG

 

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@jeanL , Try TOPN like

CALCULATE([total_teus], TOPN(10,ALLSELECTED(summary_table[od_pairs]),[total_teus],dense), ALLSELECTED(summary_table[od_pairs]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

CNENFRNL
Community Champion
Community Champion

rankings =
RANKX(
    ALLSELECTED( summary_table[od_pairs] ),
    CALCULATE( SUM( [total_teus] ) )
)

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

3 REPLIES 3
jeanL
Helper I
Helper I

@CNENFRNL @amitchandak  Thank you! both worked perfectly! 

CNENFRNL
Community Champion
Community Champion

rankings =
RANKX(
    ALLSELECTED( summary_table[od_pairs] ),
    CALCULATE( SUM( [total_teus] ) )
)

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!

amitchandak
Super User
Super User

@jeanL , Try TOPN like

CALCULATE([total_teus], TOPN(10,ALLSELECTED(summary_table[od_pairs]),[total_teus],dense), ALLSELECTED(summary_table[od_pairs]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.

Top Solution Authors
Top Kudoed Authors