Weighted Average Ignoring Zeros in Weighting and Value Ranges

andybason

Board Regular
Joined
Jan 7, 2012
Messages
217
Office Version
  1. 2016
Hello

I am trying to calculate a weighted average but some of the values in the range and some of the weightings will often be zero.

This is what I have come up with so far:

=SUMPRODUCT(O231:O240,R231:R240)/COUNTIF(R231:R240,">0")

R contains the weightings and O contains the values but it's not working. The XL2BB is below,

Can anyone see the issue?

Thank you

Cell Formulas
RangeFormula
O231:O240O231=IF(I231="",0,(I231*L231))
P231:Q240P231=IF(J231="","",(J231*M231))
R231:R240R231=(C231/$C$230)
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
At a minimum, replace COUNTIF with SUMIF.

But since 0*x = 0 and 0+x = x (i.e. the zeros make no difference), you could replace SUMIF(R231:R240 ,">0") with simply SUM(R231:R240).

And since your weights should sum to 1 and x/1 = x, you don't need the divisor at all. Simply use SUMPRODUCT as you wrote it.

This is demonstrated below.

Book1
ORS
2310.000.00
2320.000.00
2330.000.00
23423.590.38
23535.460.06
2360.000.00
23719.240.10
2382.430.04
2390.000.00
24029.130.42
241
24225.3476R242: =SUMPRODUCT(O231:O240,R231:R240)/SUMIF(R231:R240,">0")
24325.3476R243: =SUMPRODUCT(O231:O240,R231:R240)/SUM(R231:R240)
24425.3476R244: =SUMPRODUCT(O231:O240,R231:R240)
24525.3476R245: =SUM(O234*R234,O235*R235,O237*R237,O238*R238,O240*R240)
Sheet1


(The formula in R245 is the "manual" calculation of the weighted average, just for "proof of concept", not recommended.)
 
Last edited:
Upvote 0
And since your weights should sum to 1 and x/1 = x, you don't need the divisor at all. Simply use SUMPRODUCT as you wrote it.


PS (too late to edit).... I should have written: __If__ your weights sum to 1, as it appears yours do, you don't need the divisor.

I did __not__ mean to suggest that the weights "should" always sum to 1. And when they don't, we certainly do need to divide by the sum of the weights.

-----

PPS.... If you do not fully understand weighted averages (and the use of COUNTIF instead of SUMIF was not simply a "brain fart"), I suggest that you post all of the other numbers that are involved in the calculations (at least columns C, I and L) and explain their interpretation (e.g. stock price and number of shares) so that we can vet your calculation.

The formulas that I provided do correctly calculate the weighted average of __something__. But it might not be the correct weighted average for your purposes. GIGO!

For example, many people miscalculate average speed by weighting by distance, to wit: SUMPRODUCT(speeds, distances) / SUM(distances). That is indeed the weighted average of __something__ (je ne sais quoi). But in fact, the average speed calculation is weighted by __time__, to wit: SUMPRODUCT(speeds, times) / SUM(times).
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,293
Members
449,077
Latest member
Rkmenon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top