Author: Oscar Cronquist Article last updated on March 03, 2020

The SUMPRODUCT function calculates the product of corresponding values and then returns the sum of each multiplication.

The picture above shows how the SUMPRODUCT works in greater detail.

Formula in cell B7:

=SUMPRODUCT(B2:B4, C2:C4)

The SUMPRODUCT function multiplies cell ranges row by row and then adds the numbers and returns a total. The formula in cell B7 multiples values 1*4= 4, 2*5 = 10 and 3*6 =18 and then adds the numbers 4+10+18 equals 32.

Excel Function Syntax

SUMPRODUCT(array1, [array2], ...)

Arguments

array1 Required. Required. The first array argument whose numbers you want to multiply and then sum.
[array2] Optional. Up to 254 additional arguments.

Comments

The SUMPRODUCT function is one of the most powerful functions in Excel and is one that I often use. I highly recommend learning how it works.

The SUMPRODUCT function requires you to enter it as a regular formula, not an array formula. However, there are exceptions. If you use a logical expression you must enter the formula as an array formula and convert the boolean values to their equivalents.

There are workarounds to this problem which I will demonstrate in the examples below.

Note, Excel 365 subscribers do not need to enter formulas as array formulas in the examples below. Microsoft has changed how array formulas work and they are now called "dynamic arrays".

Example 1 - The basics

SUMPRODUCT function1

This example demonstrates how the SUMPRODUCT function works.

Formula in cell B7:

=SUMPRODUCT(B2:B4, C2:C4)

Step 1 - Multiplying values on the same row

The first array is in cell range B2:B4 and the second array is in cell range C2:C4.

B2:B4*C2:C4

becomes

{1;2;3} * {4;5;6}

becomes

{1*4; 2*5; 3*6}

and returns {4; 10; 18}.

The same calculations are done in column D and shown in column E, see above picture.

Step 2 - Return the sum of those products

{4; 10; 18}

becomes

4 + 10 + 18

and the function returns 32 in cell B7.

The same calculation is done E5, the sum of the products in cell range E2:E4 is calculated in cell E5. See the above picture.

Now you know the basics. Let's move on to something more interesting.

Example 2 - Use a logical expression

SUMPRODUCT function2

The image above demonstrates a formula in cell G4 that counts how many cells that is equal to the value in cell G2. Note, that this is only an example. I recommend you use the COUNTIF function to count cells based on a condition, it is designed to do that.

Formula in cell G4:

=SUMPRODUCT(--(B2:B6=$G$2))

Step 1 - Logical expression returns a boolean value that we must convert to numbers

There is only one array in this formula but something else is distorting the picture. A comparison operator (equal sign) and a second cell value (G2) or a comparison value. With these we have now built a logical expression. This means that the value in cell G2 is compared to all the values in cell range B2:B6 (not case sensitive).

B2:B6=$G$2

becomes

{"Alaska";"California";"Arizona";"California";"Colorado"}="California"

and returns

{FALSE; TRUE; FALSE; TRUE; FALSE}.

They are all boolean values and excel can´t sum these values. We have to convert the values to numerical values. There are a few options, you can:

  • Add a zero - (B2:B6=$G$2)+0
  • Multiply with 1 - (B2:B6=$G$2)*1
  • Double negative signs --(B2:B6=$G$2)

They all convert boolean values to their numerical equivalents. TRUE is 1 and FALSE is 0 (zero).

--( {FALSE;TRUE;FALSE;TRUE;FALSE})

becomes

{0;1;0;1;0}

Step 2 - Return the sum of those products

{0;1;0;1;0}

becomes

0 + 1 + 0 + 1 + 0

and returns 2 in cell G4. There are two cells containing the value "California" in cell range B2:B6.

You accomplish the same thing using the COUNTIF function or count multiple values in different columns using the COUNTIFS function. In fact, you can count entire records in a data set using the COUNTIFS function.

Example 3 - Use multiple conditions in the SUMPRODUCT function

SUMPRODUCT function3

This example shows how to use multiple conditions in the SUMPRODUCT function using AND logic. AND logic means that all conditions must be met on a given row in order to add the number to the total.

Formula in cell D10:

=SUMPRODUCT(--(B2:B8=B10), --(C2:C8=C10),D2:D8)

This formula contains three arguments, the SUMPRODUCT function allows you to use up to 30 arguments. You can make the formula somewhat shorter:

=SUMPRODUCT((B2:B8=B10)*(C2:C8=C10)*D2:D8)

This also allows you to have a lot more conditions than 30 if you like and use OR logic if you want. Example 4 demonstrates OR logic.

It is only the available computer memory that is the limit if you use this method. The formula looks like an array formula but no, you are not required to enter it as an array formula.

Step 1 - Multiplying corresponding components in the given arrays

The first logical expression B2:B8=B10 uses an equal sign to check if the values in cell range B2:B8 are equal to the value in cell B10.

B2:B8=B10

becomes

{"Alaska";"California";"Arizona";"California";"Colorado";"California";"Nevada"}="California"

and returns

{FALSE; TRUE; FALSE; TRUE; FALSE; TRUE; FALSE}.

The second logical expression is C2:C8=C10, the other logical operators you can use are:

  • = equal
  • < less than
  • > greater than
  • <> not equal to
  • <= less than or equal to
  • >= larger than or equal to

C2:C8=C10

becomes

{"Anchorage";"San Diego";"Phoenix";"Los Angeles";"Denver";"Los Angeles";"Las Vegas"}="Los Angeles"

and returns

{FALSE; FALSE; FALSE; TRUE; FALSE; TRUE; FALSE}.

The third and last logical

(B2:B8=B10)*(C2:C8=C10)*D2:D8

becomes

({FALSE; TRUE; FALSE; TRUE; FALSE; TRUE; FALSE})*({FALSE; FALSE; FALSE; TRUE; FALSE; TRUE; FALSE})*{10; 20; 40; 10; 20; 30; 10}

becomes

{0;0;0;1;0;1;0}*{10; 20; 40; 10; 20; 30; 10}

and returns

{0; 0; 0; 10; 0; 30; 0}

Step 2 - Return the sum of those products

{0; 0; 0; 10; 0; 30; 0}

becomes

10 +30

and returns 40 in cell D10.

Example 4 - Use multiple logical expressions and mathematical operators

Mathematical operators between arrays allows you to do more complicated calculations, like this:

SUMPRODUCT function4

This example shows how to use multiple conditions. A number in cell range D2:D8 is added if California is found on the corresponding row in cell range B2:B8 OR if "Las Vegas" is found in cell range C2:C8.

* - Both logical expressions must match (AND logic)

+ - Any of the logical expressions must match, it can be all it can be only one. It doesn't matter. (OR logic)

The AND logic behind this is that

  • TRUE * TRUE = TRUE
  • TRUE * FALSE = FALSE
  • FALSE * FALSE = FALSE

The OR logic works like this:

  • TRUE + TRUE = TRUE
  • TRUE + FALSE = TRUE
  • FALSE + FALSE = FALSE

Formula in cell D10:

=SUMPRODUCT(((B2:B8=B10)+(C2:C8=C10))*D2:D8)

These expressions check if California is found in cell range B2:B8 or Las Vegas is found in cell range C2:C8. They are found in row 3, 5,7 and 8.

The sumproduct function sums the corresponding values in column D and returns 70 in cell D10. 20+10+30+10 equals 70.

Download Excel file


Sumproduct-function.xlsx

Recommended articles