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
Anonymous
Not applicable

Ranking not working correctly in map

Hi,

 

I am trying to show the Top X sales person based on a slicer both in a table and on map. For that purpose I use the follwing measure as a visual filter:

Rang Salesstaff Map Sales Top X = 
VAR Ranking = RANKX(ALL(Salesstaff), [Total Sales],,DESC)
RETURN
IF(Ranking <='Top X'[TopX],'Sales'[Total Sales])

This measure works fine in the table filter, however when I use it in the map filter, it includes other salesstaff. It seems like that based on the ZIP code used in the map this meassure calculates an new ranking based on ZIP codes. Any suggestions on how I can fix this issue?

 

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous 

I change your Rank measure and achieve your goal.

New Rank Measure:

 

Rank = RANKX(ALL('Sales Staff'),CALCULATE(SUM(Sales[Sale])),,DESC,Dense)

 

Result:

1.png

Best Regards,

Rico Zhou

 

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

View solution in original post

20 REPLIES 20
Anonymous
Not applicable

Hi @Anonymous 

I build a sample table and add a rank column by calculated column.

Rank = RANKX('Table','Table'[vertragssumme],,DESC,Dense)

Table:

1.png

Then build a TopX table by rank column.

TopX = 
GENERATESERIES(MIN('Table'[Rank]),MAX('Table'[Rank]),1)

Use this table to build a slicer and build a measure.

Sales = 
var _selectvalue = SELECTEDVALUE(TopX[Value])
Return
IF(SUM('Table'[Rank])<=_selectvalue,SUM('Table'[vertragssumme]),BLANK())

Build a table visual and map visual to have a test.

Default they will show blank.

2.png

Select 10, two visuals will show top 10 values.

3.png

Or you don't need to build a slicer, you can drag rank into Filter on this page and show items when the value is less than or equal to 10, or other number you want and select apply filter.

4.png

You can download the pbix file from this link: Ranking not working correctly in map

 

Best Regards,

Rico Zhou

 

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

Anonymous
Not applicable

Thanks so much for your detailed solution @Anonymous !!!

 

However, when I use your calculated ranking column, it does not work correctly for my case, because the ranking is not dynmic based on other slicer. How would your solution work, if you had a user table and sales table with date of sale where the ranking needs adjusts based on month and year slicers?

Anonymous
Not applicable

Hi @Anonymous 

I build a new table add Year column. If you have date value in your table, you can add calculated column to get the Year and Month column.

Year = Year(Table(Date)) && Month = Month(Table(Date))

1.png

Then build a Rank measure it will dynamic by your Year and Month Slicer.

Rank = RANKX(ALLSELECTED('Table'),CALCULATE(SUM('Table'[vertragssumme])),,DESC,Dense)

Build a new TopX Table:

TopX = 
GENERATESERIES(MINX('Table',[Rank]),MAXX('Table',[Rank]),1)

New Sales Measure:

Sales = 
var _selectvalue = SELECTEDVALUE(TopX[Value])
Return
IF([Rank]<=_selectvalue,SUM('Table'[vertragssumme]),BLANK())

Build a table visual and Map visual to see our result.

Default:

2.png

Select 2019 and get the Top 3 Sales:

3.png

Select 2020 and get the Top 10 Sales:

4.png

You can download the pbix file from this link: Ranking not working correctly in maps

 

Best Regards,

Rico Zhou

 

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

Anonymous
Not applicable

Thanks for the updated solution @Anonymous However, your suggested solution has the same issue as my solution.

 

When I select the Top 5, Germany shows up with 100k in the table, which is correct. But in the map Germany shows up with 150k, because it still takes all values from the sales table in the selected year into consideration. How can I fix that?

 

image.png

Anonymous
Not applicable

Hi @Anonymous 

I change the Rank and Sales Measure as below.

 

Rank = RANKX(ALLEXCEPT('Table','Table'[Year]),CALCULATE(SUM('Table'[vertragssumme])),,DESC,Dense)
Sales = 
var _selectvalue = SELECTEDVALUE(TopX[Value])
Return
CALCULATE(SUM('Table'[vertragssumme]),FILTER('Table',[Rank]<=_selectvalue))

 

Other steps are the same as before.

Result:

1.png

You can download the pbix file from this link: Ranking not working correctly in maps

 

Best Regards,

Rico Zhou

 

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

Anonymous
Not applicable

Thanks for the promt reply @Anonymous 

 

I tried to get it to work for my scenario, but because I have a seperate date table, a sales table and a product table, I am unable to replicate your solution. Can you please have a look at the updated data model and update your solution?

 

Case_Ranking not working correctly in map 

Anonymous
Not applicable

Hi @Anonymous 

Could you share your pbix file with me by your OneDrive for Business again? I can't get access to it. Or if you have solved your problem, kindly share your workaround and mark it as a solution. More people will benefit from it. 

Best Regards,

Rico Zhou

Anonymous
Not applicable

@AnonymousThanks for your help. I have updated the link to the file.

Anonymous
Not applicable

Hi @Anonymous 

Please share your pbix file from your OneDrive for Business. Due to I don't have a permission to the pbix file you have shared with me.

 

Best Regards,

Rico Zhou

 

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

  

 

Anonymous
Not applicable

Hi @Anonymous Unfortunatly, my employer has disabled the link sharing with people outside of the organization. You should be able to download the link by pressing the download button on the top right:

 

image.png

Anonymous
Not applicable

Hi @Anonymous 

I change your Rank measure and achieve your goal.

New Rank Measure:

 

Rank = RANKX(ALL('Sales Staff'),CALCULATE(SUM(Sales[Sale])),,DESC,Dense)

 

Result:

1.png

Best Regards,

Rico Zhou

 

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

Anonymous
Not applicable

Works perfectly, thanks so much @Anonymous!

amitchandak
Super User
Super User

@Anonymous ,

You can try top N, example

Top 10 City Rank = CALCULATE([Sales],TOPN(10,all(Geography[City]),[Sales],DESC),VALUES(Geography[City Id]))

 

assume this the rank

 

City Rank = RANKX(all(Geography[City]),[Sales])

 

these are option for filter, example 

Rank Top 10= CALCULATE(if([City Rank]<=10,[Sales],BLANK()) ,VALUES(Geography[City]))  // this might not work
Rank Top 10 1 = sumx(VALUES(Geography[City]),if([City Rank]<=10,[Sales],BLANK()) )
Rank 2nd top = sumx(filter(VALUES(Geography[City]),[City Rank]=2),[Sales] ) //=2

 

refer

https://databear.com/power-bi-dax-topn-function/

 

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
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/367415

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
Greg_Deckler
Community Champion
Community Champion

@Anonymous - Your IF statement doesn't seem complete.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_DecklerPlease elaborate. Based on my knowledge, a true/false statement and an instruction on what to do when the value is true should be sufficient.

@Anonymous - Apparently you are correct, in that case it will automatically return blank if false. For some reason I thought it would never allow me to not have the false statement.

 

Your ALL should prevent recalculation at the zip code level.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Anonymous yes IF statement is correct. I guess you are using what-if parameter to determine ho may top x staff members you want, correct?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

correct @parry2k 

@Anonymous well others have provided the solution and see if it works, if not then reply it here and can look into it. Cheers!

 

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

This is the top 10 table, where the measure works correctly.

image.png

Markus, Reinhard and Peter show up on the map.

image.png

I believe this is because their total based on the zip still gets them into the Top 10, but the ZIP code should not be considered for this ranking.

 

Any idea @parry2k@Greg_Deckler@amitchandak?

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!

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