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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
johnyip
Solution Sage
Solution Sage

Rank sales based on categories and sub-categories

The table has 3 columns, [Company], [market], [sales], and the data is like the following:

 

Companymarketsales
ALOCAL1000
BLOCAL2000
CLOCAL3000
DEUROPE4000
EEUROPE5000
FEUROPE6000
GASIA1000
HASIA2000
IASIA3000

 

I want to rank the sales using market as the parent, and the company as the child, with the following expected result:

CompanyMarketSalesRanking
ALOCAL10003
BLOCAL20002
CLOCAL30001
DEUROPE40003
EEUROPE50002
FEUROPE60001
GASIA10003
HASIA20002
IASIA30001

 

I tried many DAX on my own and cannot come up with an answer to achieve that. I would be appreicated if anyone of one can assist me.



Please mark my post as the solution if this answers your question!
Appreciate your Kudos !!
2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@johnyip , Try a new column rank

Rank = rankx(filter(Table, [Market] = earlier([Market])), [Sales])

 

a measure rank

 

Rank = rankx(filter(all(Table[Market], Table[Comapany]), [Market] = max([Market])),calculate(Sum( [Sales])))

 

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

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

Jihwan_Kim
Super User
Super User

Hi,

One of ways to solve this is to wrtie the measure like below.

Please check the below picture and the attached pbix file.

 

Sales Measure: =
SUM( Data[sales] )
 
Ranking measure: =
VAR currentmarket =
MAX ( Data[market] )
VAR currentsales = [Sales Measure:]
VAR newtable_filter =
FILTER (
ALL ( Data ),
Data[market] = currentmarket
&& [Sales Measure:] >= currentsales
)
RETURN
COUNTROWS ( newtable_filter )
 
Picture1.png

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

One of ways to solve this is to wrtie the measure like below.

Please check the below picture and the attached pbix file.

 

Sales Measure: =
SUM( Data[sales] )
 
Ranking measure: =
VAR currentmarket =
MAX ( Data[market] )
VAR currentsales = [Sales Measure:]
VAR newtable_filter =
FILTER (
ALL ( Data ),
Data[market] = currentmarket
&& [Sales Measure:] >= currentsales
)
RETURN
COUNTROWS ( newtable_filter )
 
Picture1.png

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thank you for the answer, this works well too 🙂



Please mark my post as the solution if this answers your question!
Appreciate your Kudos !!
amitchandak
Super User
Super User

@johnyip , Try a new column rank

Rank = rankx(filter(Table, [Market] = earlier([Market])), [Sales])

 

a measure rank

 

Rank = rankx(filter(all(Table[Market], Table[Comapany]), [Market] = max([Market])),calculate(Sum( [Sales])))

 

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

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

Thanks for the answer, the output of my pbix file is just like what I expected. But it is unfortunate to say that I cannot share the sample data here, sorry for that.



Please mark my post as the solution if this answers your question!
Appreciate your Kudos !!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.