Reputation: 6769
I would like to use SUMPRODUCT
function for the following scenario
A B
1 ""
2 1
where the value ""
was entered using the formula =""
as part of an IF
condition like this: IF (condition_is_true, value, "")
. I would like to visualize in my table when I have an empty value from zero value, that is why in the IF
statement I am using ""
instead of 0
(that would produce the right result).
I am using SUMPRODUCT
as follow:
SUMPRODUCT(A1:A2, B1:B2)
expecting to return the value 2
For excluding the ""
cells, I was expecting that the following should work:
SUMPRODUCT(A1:A2, --(B1:B2<>""), B1:B2)
but in this case, it doesn't work because the cell is not blank, I was trying several options but in all cases, I am getting #VALUE
as result in all cases.
Note: I found some similar question but not addressing this specific case.
UPDATE: I realized working on my real situation, the issue was not the blanks, but rather trying to use SUMPRODUCT
function when one argument is on row format and the other one in column format, for some reason it doesn't work, transposing the second argument using TRANSPOSE
function works, I don't know why. The following picture shows the situation
Upvotes: 0
Views: 1339
Reputation: 5902
I am using O365
and your first formula works for me for conditional blanks.
=SUMPRODUCT(A1:A2, B1:B2)
for test purpose, B1
has =IF(C1<>"",1,"")
. See below snapshot.
You can use an IF
formula inside SUMPRODUCT
like below to get around the issue.
=SUMPRODUCT(A1:A2, IF(B1:B2<>"",B1:B2,0))
Edit:
SUMPRODUCT
is an array formula and it requires the arrays involved in the operation of the same dimension & size.
So in principle, when we multiply two columns the data array is (note semicolon between entries):
{A1;A2;A3;A4;....An}
whereas when it is spread across a row then it is (note comma between entries):
{A1;B1;C1;D1;E1....}
So when you try to implement it for data spread in rows with columnar data, the array size criteria is fulfilled but the dimension criteria is not and therefore it returns an error! Applying TRANSPOSE
changes the array to matching dimension and therefore returns result on expected lines.
Upvotes: 2
Reputation: 37125
You can omit 3rd array of your formula. Try-
=SUMPRODUCT(A1:A2, --(B1:B2<>""))
Upvotes: 1