SUMPRODUCT((range={“this”;“that”})*(other conditions)) return N/A if some cell of range does not meet this or that

余生长醉 提交于 2019-12-08 02:24:00

问题


Data set:

A|B

1|a     
2|b     
3|c

Formula:

=SUMPRODUCT((B1:B3={"a";"b"}))

The sumproduct return NA there. I don't get why. I want it to return 2.

If I add c to the condition it correctly returns 3.

What am I my missing ?


回答1:


You are comparing an array of size 1x3 to an array of size 1x2 which is not allowed. (If you compare two vertical arrays, they must be the same size. This is why the problem is fixed when you add "c" to the formula.)

You need to compare a 1x3 array to a 2x1 array.

This expression:

B1:B3={"a";"b"}

Returns:

{TRUE;TRUE;#N/A}

SUMPRODUCT cannot handle logical (TRUE/FALSE) values so you must add 0, multiply by 1, or perform double negative operator to change to an array of numerical values.

So... this:

--(B1:B3={"a";"b"})

Returns:

{1;1;#N/A}

Performing SUMPRODUCT on this will still return #N/A since the array contains #N/A.

But if you do this: (Note the comma instead of semicolon)

B1:B3={"a","b"}

Now you get:

{TRUE,FALSE;FALSE,TRUE;FALSE,FALSE}

Note this returns a 2x3 array.

Perform double negative operator and you get this:

{1,0;0,1;0,0}

Now performing SUMPRODUCT will return 2, as you expect.

The final formula you need is:

= SUMPRODUCT(--(B1:B3 = {"a","b"}))




回答2:


You'r comparing a horizontal range vs. a vertical range. However your delimiter is wrong in case of English version. Also, with the right , as delimiter, your comparison will return a range of TRUE and FALSE values.

Wrap your comparison in a double negative or multiply it by 1. e.g.:

=SUMPRODUCT(--(B1:B3={"a","b"}))

Or:

=SUMPRODUCT((B1:B3={"a","b"})*1)

This will change TRUE into 1 and FALSE into 0, values your SUMPRODUCT can actually sum.

A more comprehensive explaination on why adding a "c" would work given by @Jerry on a failry similar question I once had can be found here



来源:https://stackoverflow.com/questions/57091759/sumproductrange-thisthatother-conditions-return-n-a-if-some-cell-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!