can you explain this formula to me please.
=SUMPRODUCT(--(A1:A5="Jan"),--(B1:B5="John"),C1:C5)
SUMPRODUCT returns the "sum of products" which is simply arrays of numbers
multiplied together then those results are added up to arrive at the final
result. To make this work we need to convert logical tests to numeric values
that can be multiplied together.
Each of these expressions will return an array of logical values TRUE or
FALSE:
(A1:A5="Jan")
(B1:B5="John")
T = TRUE, F = FALSE
A1 = Jan = T
A2 = Jan = F
A3 = Jan = F
A4 = Jan = F
A5 = Jan = F
B1 = John = T
B2 = John = F
B3 = John = T
B4 = John = F
B5 = John = T
One way to convert those logical values to numbers is to use the double
unary "--". The "--" coerces the TRUE and FALSE to numeric values. TRUE = 1,
FALSE = 0
--(A1 = Jan) = 1
--(A2 = Jan) = 0
--(A3 = Jan) = 0
--(A4 = Jan) = 0
--(A5 = Jan) = 0
--(B1 = John) = 1
--(B2 = John) = 0
--(B3 = John) = 1
--(B4 = John) = 0
--(B5 = John) = 1
Now, we have 3 arrays of numbers that can be multiplied together:
The 1st array is --(A1:A5="Jan")
The 2nd array is --(B1:B5="John")
The 3rd array is C1:C5
1*1*2 = 2
0*0*3 = 0
0*1*4 = 0
0*0*2 = 0
0*1*3 = 0
Now SUMPRODUCT adds up these results of the multiplication to arrive at the
final result:
=SUMPRODUCT({2;0;0;0;0}) = 2
So: Jan and John = 2