H
Harlan Grove
I'm too lazy at the moment to find the thread in which someone asked about the
relative merits of SUMPRODUCT vs SUM(IF(..)) when there were multiple
conditions. The question deserves a reply.
There's a third way to sum conditionally, SUMIF, but it only accepts criteria
that would be applied singly. (I'm ignoring the fact that it can take an array
second argument of mutually exclusive criteria.) If a single criterion is needed
and the values to be summed are in a single area range (rectangular block of
cells on a single worksheet), then SUMIF is the best way to sum conditionally.
For more complicated conditional sums, usually involving multiple criteria, both
SUM(IF(..)) and SUMPRODUCT can be used in most cases. The following formulas
should give the same results.
=SUM(IF((Range>0)*(MOD(Range,5)=0),Range)
=SUMPRODUCT(--(Range>0)*(MOD(Range,5)=0),Range)
The SUM(IF(..)) formula must be entered as an array formula, but the SUMPRODUCT
formula needn't be. As an educated guess, this means the formula parser is
involved in evaluating SUM(IF(...)), but SUMPRODUCT itself can handle the entire
evaluation. Usually this means SUMPRODUCT will recalculate faster than
equivalent SUM(IF(..)) calls. On the other hand, if any of the criteria involve
error trapping, SUM(IF(..)) is the only sensible option. For example,
=SUM(IF(ISNUMBER(Range),IF(Range>0,Range)))
=SUMPRODUCT(IF(ISNUMBER(Range),--(Range>0),0),Range)
should return the same results if *both* were entered as array formulas. This is
a quirk of how Excel evaluates IF(..) in array contexts. If the IF function
should return an array result, the formula containing must *always* be entered
as an array formula. Entering SUMPRODUCT formulas as array formulas eliminates
its recalc speed, at which point SUM(IF(..)) is better because it involves less
typing.
So, when error trapping isn't an issue, SUMPRODUCT recalcs faster and doesn't
need to be entered as an array. Those are the benefits compared to SUM(IF(..)).
On the other hand, SUM(IF(..)) is more general and is the most practical way to
handle error trapping.
relative merits of SUMPRODUCT vs SUM(IF(..)) when there were multiple
conditions. The question deserves a reply.
There's a third way to sum conditionally, SUMIF, but it only accepts criteria
that would be applied singly. (I'm ignoring the fact that it can take an array
second argument of mutually exclusive criteria.) If a single criterion is needed
and the values to be summed are in a single area range (rectangular block of
cells on a single worksheet), then SUMIF is the best way to sum conditionally.
For more complicated conditional sums, usually involving multiple criteria, both
SUM(IF(..)) and SUMPRODUCT can be used in most cases. The following formulas
should give the same results.
=SUM(IF((Range>0)*(MOD(Range,5)=0),Range)
=SUMPRODUCT(--(Range>0)*(MOD(Range,5)=0),Range)
The SUM(IF(..)) formula must be entered as an array formula, but the SUMPRODUCT
formula needn't be. As an educated guess, this means the formula parser is
involved in evaluating SUM(IF(...)), but SUMPRODUCT itself can handle the entire
evaluation. Usually this means SUMPRODUCT will recalculate faster than
equivalent SUM(IF(..)) calls. On the other hand, if any of the criteria involve
error trapping, SUM(IF(..)) is the only sensible option. For example,
=SUM(IF(ISNUMBER(Range),IF(Range>0,Range)))
=SUMPRODUCT(IF(ISNUMBER(Range),--(Range>0),0),Range)
should return the same results if *both* were entered as array formulas. This is
a quirk of how Excel evaluates IF(..) in array contexts. If the IF function
should return an array result, the formula containing must *always* be entered
as an array formula. Entering SUMPRODUCT formulas as array formulas eliminates
its recalc speed, at which point SUM(IF(..)) is better because it involves less
typing.
So, when error trapping isn't an issue, SUMPRODUCT recalcs faster and doesn't
need to be entered as an array. Those are the benefits compared to SUM(IF(..)).
On the other hand, SUM(IF(..)) is more general and is the most practical way to
handle error trapping.