Consider the following:
A B C
----------------
1 a c 1
2 b f 2
3 a c 3
...
6 a c 4
The goal here is to use a conditional SUMPRODUCT so that when the values in row 6 match values in their respective column, the SUMPRODUCT is computed. Here is the interesting thing.
When using:
=SUMPRODUCT((A3:A5=A1),(B3:B5=B1),C3:C5)
the input arguments are evaluated as:
=SUMPRODUCT({TRUE, FALSE, TRUE},{TRUE, FALSE, TRUE},{1, 2, 3})
but the result is 0.
Now when casting the boolean TRUEs and FALSEs to their 1 and 0 counterparts ‘before’ evaluation of the formula with a mathematical operator, the proper result populates:
=SUMPRODUCT(--(A3:A5=A1),--(B3:B5=B1),C3:C5)
or
=SUMPRODUCT(ABS(A3:A5=A1),ABS(B3:B5=B1),C3:C5)
or
=SUMPRODUCT((A3:A5=A1)^2,(B3:B5=B1)^2,C3:C5)
etc…,
eventually evaluates to 1s and 0s once the mathematical operator is applied,
=SUMPRODUCT({1, 0, 1},{1, 0, 1},{1, 2, 3})
and we get the proper value.
We having been racking our minds over Excel can’t seem to properly evaluate it’s own inputs. We think there is a line of code missing the the SUMPRODUCT compiled code that converts the TRUEs and FALSEs to 1 and 0 and error trapping simply returns a 0.
Any thoughts?
Most functions don’t coerce logical values to numbers in array arguments, and IMHO it’s preferable to err on the side of consistency rather than introducing new behavior for a few functions. Coercion also has a performance overhead associated so should only be implemented when needed.
That said some extra functions like
AVERAGEA,VARA, etc. were added that do treat logical values as numbers (and text values as zero) so i guess a SUMPRODUCTA function could have been added too but that might also add confusion and to application bloat. I believe the purpose of these was for compatablity with Lotus 123. There is also a setting for Transition Formula Evaluation in Excel Options | Advanced, which when activated will treat TRUE/FALSE as numbers in calculations likeSUMbut many functions don’t seem to respond to this as expected.