2

上下文是 我正在使用调整后的 sumproduct 公式来计算加权平均值。

问题是 sumproduct 包含数组中的空单元格。=> 加权平均值计算不正确。

问题是 如何编辑 sumproduct 以排除数组中的空单元格?

或者 是否有另一种干净整洁的解决方案?

4

1 回答 1

7

In the sumproduct, to exclude empty cells, suppose you're using it on range A1:A100, you could do the following:

= Sumproduct((A1:A100),--(A1:A100<>""))

That second criteria will ensure that you're only looking at cells that have a value in them...

As an explanation (A1:A100<>"") will return an array of True False, where, if there is a value in the cell, it returns true, otherwise, false. Then, including the -- before it, it converts True/False to 1/0. So, in effect, you're multiplying empty cells by a zero (excluding from the formula) and non-empty cells by 1 (including them in the formula).

The --(logical statement for my array) is a very useful trick to use with SumProduct() in MANY different ways!!

于 2013-09-04T14:00:26.133 回答