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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

RANKX with TOPN in measure always returns 1

I am trying to get a measure to give me a rank value but it always returns 1. 
 
The tables of both measures are related, Using a TOPN filter with the measure for the "Werknemers" table based on the Kosten measure does show me that the Kosten measure works.

 

-Measure
Kosten = CALCULATE(SUMX(Behandeling,RELATED(Specialisten[Kostprijs])*Behandeling[Duur]))

-Measure
DuursteWN = RANKX(TOPN( 10, ALLSELECTED(Werknemers), MeasureTable[Kosten], ASC, Werknemers[Werknemer], ASC), MeasureTable[Kosten])

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Not sure what you are trying using thtat

Try TOPn like

DuursteWN = calculate([Kosten]TOPN(10,allselected(table[Werknemers]),[Kosten],DESC), values(table[Werknemers]))

 

Or Rank like and then use visual level filter 

DuursteWN = RANKX(ALLSELECTED(Werknemers), MeasureTable[Kosten],,desc, desnse)


For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
 

TOPN: https://www.youtube.com/watch?v=QIVEFp-QiOk&list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&index=42

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

3 REPLIES 3
Anonymous
Not applicable

Hi @Anonymous ,

 

I found an article  that explains this question:

 

"The RANKX() function ranks individual data rows according to a certain ranking attribute. It’s result is a numerical value associated with each and every single row of the data table.

 

Although the TOPN() function sounds the same,it does not return a value for each row in the data table. It returns a table that contains the top N items (N is the number you specified in the first argument) from the original data table according to the ranking attribute you specified.

 

In itself this is pretty useless, since you cannot display this data in any way. If you could it would be an alternative way to get a top N ranking to RANKX.

 

To make TOPN useful you need to wrap it in another function, such as SUMX or AVERAGEX.“

 

Hope it helps,


Community Support Team _ Caitlyn

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

 

 

amitchandak
Super User
Super User

@Anonymous , Not sure what you are trying using thtat

Try TOPn like

DuursteWN = calculate([Kosten]TOPN(10,allselected(table[Werknemers]),[Kosten],DESC), values(table[Werknemers]))

 

Or Rank like and then use visual level filter 

DuursteWN = RANKX(ALLSELECTED(Werknemers), MeasureTable[Kosten],,desc, desnse)


For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
 

TOPN: https://www.youtube.com/watch?v=QIVEFp-QiOk&list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&index=42

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi,

Thanks for the help. I think I can get most of my things fixed with your second solution!

I still have a questions. After reading those articles and docs from windows I still do not understand something. 

Why does the TOPN not work in RANKX? I don't want to make similar mistakes in the future. 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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