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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
rauerfc
Frequent Visitor

RANKX returning variable, TOP 1, 2, 3, 4

I have a table that has sales by month, account manager, and MRK.

I need that the measure returns the TOP 1 selling MRK and another one for 2, 3, and 4.

Output = 130 or 40 or 110

Each measure will be used in 4x charts, each one for the TOP 1,2,3,4, and this could vary by Account Manager.

Each Acc Manager could have differents TOP 1, 2, 3, 4 consequently, different charts.

Sample of dataset:

 

MRKManagerMonthQuantity Sales
10921Mar-219
10952Mar-212
40921Mar-2122
40952Mar-2153
404147Mar-2138
4024829Mar-216
1104147Mar-210
130951Mar-21210
150943Mar-2158
150947Mar-21307
150951Mar-21324
150952Mar-2126
17041687Mar-21129
170921Mar-212
170922Mar-2112
170923Mar-21201
170924Mar-2185
170943Mar-218
170947Mar-2128
170951Mar-21221
170952Mar-2126
1703627Mar-2150
1704147Mar-2152
2 ACCEPTED SOLUTIONS

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

Anonymous
Not applicable

Hi @rauerfc ,

 

Please try the following formula to create measures :

sum = CALCULATE(SUM('Table'[Quantity Sales]),ALLEXCEPT('Table','Table'[MRK]))
rank = RANKX(FILTER(ALL('Table'),'Table'[Manager]=MAX('Table'[Manager])),[sum],,DESC,Dense) 

If you want to separately get the rank value , you could use this:

Top 1 MRK = CALCULATE(MAX('Table'[MRK]),FILTER('Table',[rank]=1))

The final output is shown below:

rank.PNG

Best Regards,
Eyelyn Qin
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

8 REPLIES 8
Anonymous
Not applicable

Hi @rauerfc ,

 

Please try the following formula to create measures :

sum = CALCULATE(SUM('Table'[Quantity Sales]),ALLEXCEPT('Table','Table'[MRK]))
rank = RANKX(FILTER(ALL('Table'),'Table'[Manager]=MAX('Table'[Manager])),[sum],,DESC,Dense) 

If you want to separately get the rank value , you could use this:

Top 1 MRK = CALCULATE(MAX('Table'[MRK]),FILTER('Table',[rank]=1))

The final output is shown below:

rank.PNG

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

Ashish_Mathur
Super User
Super User

What result are you expecting.  Explain the question clearly and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I need one measure that's going to calculate the TOP 1 selling MRK.

So if I select this Acc. Manager, the best-selling MRK will be 130.

And another measure to return the second best, third best, and fourth-best.

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you for your reply. 

I used your solution and it worked, is giving me the best selling, second best etc. 

And now my goal is to use this as a filter for the graph, for example:

So I want to filter information from the second-best for this graph:

rauerfc_0-1620055052590.png

I'm using your formula: 

mrk_cons_2 = CALCULATE(FIRSTNONBLANK(TOPN(1, VALUES(tab_mrk[MRK]),[sum_rank]),1), FILTER(VALUES(tab_mrk[MRK]),[rank_mrk]>1))

 

You are welcome.  So what problem are you facing?  Please be clear.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

So, each account manager has a different best selling, second best, third best MRK. 

My visualization was built to show 4 graphs that will return the same information (Coverage), for the first, second, third, and fourth best-selling MRK. 

How can I show only information from the best selling in the first graph, 2, 3 and so?

rauerfc_0-1620088255099.png

 I'm trying to filter with the rankx selecting 1 and isn't working:

rauerfc_1-1620088487851.png

rank_mrk = RANKX(ALLSELECTED(tab_mrk[MRK]),[sum_rank],, DESC, Dense)

 

Hi,

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.