Sumproduct separators

hawaean

New Member
Joined
Aug 25, 2016
Messages
36
Hi all,

Just a quick Excel question on sumproduct functions. Are there certain cases where you use "," verses "*" between criterias? Does it matter?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Just a quick Excel question on sumproduct functions. Are there certain cases where you use "," verses "*" between criterias? Does it matter?

Not entirely, most of the time. Often, it is a personal preference. But there are instances where "*" must be used.

The form of the SUMPRODUCT usage is: SUMPRODUCT(array1, array2, array3,....). Each "array" is called a parameter.

Alternatively, we could write SUMPRODUCT(array1*array2, array3), and that is usually equivalent.

Some exceptions:

1. If array2 has nonnumeric text, array1*array2 will result in a #VALUE error. On the contrary, SUMPRODUCT(array1, array2, array3) will work because SUMPRODUCT ignores elements of parameters that are text. Caveat: SUMPRODUCT also ignores numeric text in array2. So if array2 contains only numeric values and numeric text, array1*array2 is the correct choice if you intend for SUMPRODUCT to include the numeric text in the calculation.

2. if array1 is a column, array2 is a row, and array3 is 2-dimensional, we must write SUMPRODUCT(array1*array2, array3) because array1*array2 produces a 2-dimensional array. If we write SUMPRODUCT(array1, array2, array3), that produces a #VALUE error because the parameters are not the same shape.

Some examples where the use of "," or "*" does not matter much:

SUMPRODUCT(--(A1:A100=X1), --(B1:B100>Y1), C1:C100)
or
SUMPRODUCT((A1:A100=X1)*(B1:B100>Y1), C1:C100)

If you prefer the first form, it is usually fine to use what you prefer.

Technically, the second form is more efficient, especially when the ranges are very much larger.

The first form creates 2 temporary arrays, which must persist while SUMPRODUCT does its calculations.

The second form collapses the 2 temp arrays into one array that must persist while SUMPRODUCT does its calculations.

[EDIT] On the other hand, the second form creates 3 temp arrays while processing the first two parameters.

Also, the first form might perform 4 additional arithmetic operations (the double negates) than the second form.

[EDIT] On the other hand, Excel might be clever enough to recognize double negate, and it might not preform an arithmetic operation at all; just the required transformation to numeric values.

That said, there might be a performance trade-off between doing the multiplication during parameter processing v. multiplication internally while SUMPRODUCT does its calculations.

That is why it is better to write the formula according to your preference: it is too difficult and questionable to predict any performance preference.
 
Last edited:
Upvote 0
The comma syntax is native to SUMPRODUCT. The star syntax has been probably introduced by Longre by analogy to an array-processing SUM formula:

{=SUM(A2:A10*(B2:B10="X"))}

Thus:

=SUMPRODUCT(A2:A10*(B2:B10="X"))

while respecting the native comma syntax, we would have something like:

either...

=SUMPRODUCT(A2:A10,(B2:B10="X")+0)

or

=SUMPRODUCT(A2:A10,--(B2:B10="X"))

+0 and -- are so-called coercers which change TRUE and FALSE (result) values to 1 and 0. Coercion is necessary because SUMPRODUCT requires numbers.

Note that (B2:B10="X")*1 or 1*(B2:B10="X") or 0+(B2:B10="X") or (B2:B10="X")^1, etc. all can effect the required coercion.

1. What is the most efficient, the comma syntax or the star syntax? Most of the (early) assessments indicate the comma syntax as faster. Some people recently shows signs of a reversal to the star syntax.

2. One obvious disadvantage of the star syntax is that it does not tolerate text (including blanks) in the sum range. That is,

=SUMPRODUCT(A2:A10*(B2:B10="X"))

will fail if A2:A10 has any blank or other text, while SUMPRODUCT natively does not care just like SUM.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top