更新时间:2023-02-06 12:48:28
我同意COUNTIF(S)
/SUMIF(S)
的行为对于空字符串而言令人沮丧.
The behaviour of COUNTIF(S)
/SUMIF(S)
I agree is a touch frustrating with respect to null strings.
您可以尝试:
=SUM(SUMIF(A:A,{"?*",">=0"},B:B))
如果A列中的数字严格为非负数,或者,如果不是:
if the numbers in column A are strictly non-negative, or, if not:
=SUM(SUMIF(A:A,{"?*",">=0","<0"},B:B))
或者,您可以切换到SUMPRODUCT
,它不会受到对空字符串的这种模棱两可的处理:
Alternatively you can switch to SUMPRODUCT
, which does not suffer from such ambiguous handling of null strings:
=SUMPRODUCT(0+(A1:A15<>""),B1:B15)
尽管它有一个缺点,与COUNTIF(S)
/SUMIF(S)
不同,您不能随意地引用任意数量的单元格而不会影响性能(因此,我选择的上一行引用为15):实际上,在SUMPRODUCT
中使用整个列引用是一个灾难性的想法.
though which has the drawback that, unlike with COUNTIF(S)
/SUMIF(S)
, you cannot arbitrarily reference as many cells as you wish without detriment to performance (hence my choice of an upper row reference of 15): in fact, the use of entire column references within SUMPRODUCT
is a disastrous idea.
致谢