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
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

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

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

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
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
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.