View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Harlan Grove[_2_] Harlan Grove[_2_] is offline
external usenet poster
 
Posts: 1,231
Default Adding numerical values based on multiple values in another column

"Bernard Liengme" wrote...
Why not just
=SUMPRODUCT((A1:A5="red")+(A1:A5="green"),B1:B5 )
No need for "- -" since the addition operator will coerce logical
values to numeric

....

For another reason,

=SUM(SUMIF(A1:A5,{"red";"green"},B1:B5))

is more efficient both in terms of storage and recalc speed. And it's
more general (not that this is an issue in this instance), i.e.,

=SUM(SUMIF(A:A,{"red";"green"},B:B))

works, while

=SUMPRODUCT((A:A="red")+(A:A="green"),B:B)

will fail in XL2003 and prior versions.