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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
YBZ
Helper III
Helper III

total of Weighted Average not summing up

Hi all,

 

I am stuck with a formula on how to calculate a weighted average. I see that there are already similar questions posted, but my issue is with more that I have it correct on a row level, but my total doesn't match with how I expect. 

 

My data source is a report that consists of total hours and total cost for every department. While the hourly rate is the total cost divided by the total hours. The aim is to have however one final weighted rate. 

 

1) First I created the rate per department that calculates the hourly cost

 

Rate = sumx('OC 23 (2)';'OC 23 (2)'[YTD actuals])/sumx('OC 23 (2)';'OC 23 (2)'[YTD QTY])*1000

 

2) Afterwards I created a measure to create the total hours as I had other active filters on the page

 

total = calculate(sum('OC 23 (2)'[YTD QTY]);ALL('OC 23 (2)'[Department]))

 

3) Weighted percentage is the hours per department, divided by the total hours

 

Weighted percentage = divide(sum('OC 23 (2)'[YTD QTY]);[total])

 

4) Weighted rate is the weighted percentage per department, multiplied with the Rate

 

Weighted rate = calculate([Rate]*[Weighted percentage])

 

 

Final results looks as followed : 

 

DepartmentYTD QTYYTD actualsRatetotalWeighted percentageWeighted rate
a03000Infinity425520.00NaN
b0415Infinity425520.00NaN
c06Infinity425520.00NaN
d29451565425520.001
e885546300425520.0013
f4540880425520.001
g5106891352425520.0116
h158526011641425520.0461
i430429998425520.0110
j71812031675425520.0228
k2252871276425520.017
l4926631349425520.0116
m15081447960425520.0434
n424148701148425520.10114
o1042132051425520.005
p517079531538425520.12187
q05841Infinity425520.00NaN
r81417382136425520.0241
s314636471159425520.0786
t11131059952425520.0325
u955853893425520.0220
v1573682342425520.009
w8685984425520.002
x4119992431425520.0123
12033251599425520.008
216891521901425520.0436
3372350531357425520.09119
410031106171058425520.24250
51431691182425520.004
671212051693425520.0228
701586Infinity425520.00NaN
80199Infinity425520.00NaN
90274Infinity425520.00NaN
100252Infinity425520.00NaN
111655913583425520.0014
123448522481425520.0120
13174431641815425520.0474
14732423309425520.006
151296224842425520.0015
160262Infinity425520.00NaN
170727Infinity425520.00NaN
1801Infinity425520.00NaN
1900Infinity425520.00NaN
2066911385425520.002
211051461396425520.003
223824251113425520.0110
231652131289425520.005
2491513591485425520.0232
254443970425520.001
2632672132425520.002
2766731120425520.002
280-23-Infinity425520.00NaN
 425526906016234255211623

 

Now the issue is that with the total of the column Weighted rate. It would normally need to sum up the totals of every row to come to the final result. I am however not sure on how to do it, therefore trying to get some assistance on the forum as I am in general struggling with totals in other reports 🙂 

 

Regards and thanks in advance,

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@YBZ , The last one should be like

 

Weighted rate = sumx(Values(Table[Department]), calculate([Rate]*[Weighted percentage])) 
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

3 REPLIES 3
YBZ
Helper III
Helper III

Thanks for prompt reply. I understand the formula. Now I would only need to delete the NaN values. Any idea how I can exclude them in my measure? 

Manage to solve it with iferror. Thanks for the advice on the total , it works! 🙂

amitchandak
Super User
Super User

@YBZ , The last one should be like

 

Weighted rate = sumx(Values(Table[Department]), calculate([Rate]*[Weighted percentage])) 
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.