excelexcel-formulaweighted-average

Excel: How to take a weighted average where blank values cause proportional weighting shifts


I have five categories. Each category has a weight in row 2 and a value in row 3. In cell G3 I'd like to have a formula that takes the weighted average of all of the categories.

The major caveat, some categories will not have values. If a category has a blank value, its weighting should be evenly distributed to the remaining categories that do have values, and then the weighted average should be taken. See Below for two examples:

enter image description here

In this photo, cell C3 is missing a value. There are 4 categories remaining that do have values. So its weighting of 0.2 will be redistributed four ways, so each of the remaining categories will have have (02./4 =0.05) increase in their weightings in the weighted average. The highlighted cell is the desired result.

I will further illustrate with one additional scenario:

enter image description here

In the above scenario there are two categories with missing values and both have a weighting of 0.15. There are 3 categories with values. So each missing category will redistribute 0.15/3 = 0.05 weighting to the three remaining categories. So each category will have an increased weighting of 2*0.05 = 0.1 because of the 2 missing categories. The yellow box displays the correct weighted average.

One further caveat, it would be great if the formula could be dynamic enough to work for ranges of larger than 5 categories. Any ideas on how to implement something like this?


Solution

  • This seems to work for me - I have a feeling it could be simplified, but it just works through the steps outlined in the question:

    =SUMPRODUCT(B2:F2*B3:F3)+SUMPRODUCT(SUMPRODUCT((B3:F3="")*B2:F2)*B3:F3)/COUNT(B3:F3)
    

    enter image description here

    If the blank cells are not actually blank but contain "" returned as the result of a formula, you could try

    =SUMPRODUCT(B2:F2*N(+B3:F3))+
    SUMPRODUCT(SUMPRODUCT((B3:F3="")*B2:F2)*N(+B3:F3))/COUNT(B3:F3)
    

    as suggested by the brilliant @XOR LX in this answer