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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
JMD22Si
Frequent Visitor

How to Calculate Rank of category between two table sums - Please forgive the weak subject.

Hello PB'ers!  Looking for some assistance here.  Fairly new to Power BI but have a decent understanding for a beginner from usage and reverse engineering.    May data is extensive 23 tables, largest having 4.1m rows. 

 

Here is my sample data that represents what I'm trying to achieve.  There are three service stations that generate sales including Oil Changes and Tire Rotations.  For example simplicty, I've only added one fow for each month / service type, but in the actual data there are many rows per month / service. e.g. Store A / Jan / Oil Change / $50 x4.

 

I'm looking to Sum the revenue by service as a percentage of total Sales, and then Rank each store.  E.g  Store A in Jan, Oil Changes were 2.8% of Sales and Ranks 2nd behind Store B.  Store C had no Oil Changes in Jan.

StoreMonthSales
AJan6999
AFeb8025
AMar10255
BJan4900
BFeb5000
BMar6025
CJan10000
CFeb9950
CMar13000
StoreMonthServiceRevenue
AJanOil Change200
AJanTire Rotation100

A

MarOil Change300
BJanTire Rotation500
BFebOil Change250
BMarOil Change150
BMarTire Rotation100
CFebOil Change600
CMarOil Change

1000

   

 

 

Thank you for your consideration,

2 REPLIES 2
artemus
Microsoft Employee
Microsoft Employee

This is a bit technical, but...

 

Start by creating an aggregate function. You can prototype this by starting with a table filtered to only one Month. Next you would group by both Store and Service and then add a aggregate of sum of Revenue. From here you can do a merge of the table with itself using the Service name as the join key. This will add an inner join column. By clicking on the right corner of the join column, you can choose to aggregate by sum of Revenue. This gives the total revenue per service. Getting the percentage is simply adding a column with dividing the revenue of a store by the total revenue of the service. To add rank, sort the table by percentile descending followed by adding an index column (note in case of tie, an arbitary decision is made as to what is higher). 

 

Now that you have a prototype, enter the advanced editor and add to the start of the query:

(monthTable) =>

 Delete the steps where you filter the table to a single month, and replace the following's step's reference to the step you deleted with monthTable. This will give you a function that applies the transform to any month. Change the name of this query to ApplyMonthlyStats.

 

Finally, in a new query, take your table, perform a group by and choose the count aggregate on revenue column. Then in the formula bar, replace "each List([revenue])" with "ApplyMonthlyStats". Now expand the resulting table column, and you are done.

Wow, thanks for this Artemus!   I will see if I understand enough to put your text into action 🙏

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors