Excel SUMPRODUCT function with formula examples

The tutorial explains the basic and advanced uses of the SUMPRODUCT function in Excel. You will find a number of formula examples to compare arrays, conditionally sum and count cells with multiple criteria, calculate a weighted average and more.

When you hear the name of SUMPRODUCT for the first time, it may sound like some useless formula that performs an ordinary sum of the products operation. But that definition does not show even a tiny fraction of what Excel SUMPRODUCT is capable of.

In fact, SUMPRODUCT is a remarkably versatile function with many uses. Due to its unique ability to handle arrays in smart and elegant ways, SUMPRODUCT is extremely useful, if not indispensable, when it comes to comparing data in two or more ranges and calculating data with multiple criteria. The following examples will reveal the full power of SUMPRODUCT and its effectiveness will become crystal clear.

Excel SUMPRODUCT function - syntax and uses

Technically, the SUMPRODUCT function in Excel multiplies the numbers in the specified arrays, and returns the sum of those products.

The syntax of the SUMPRODUCT function is simple and straightforward:

SUMPRODUCT(array1, [array2], [array3], …)

Where array1, array2, etc. are continuous ranges of cells or arrays whose elements you want to multiply, and then add.

The minimum number of arrays is 1. In this case, a SUMPRODUCT formula simply adds up all of the array elements and returns the sum.

The maximum number of arrays is 255 in Excel 365 - 2007, and 30 in earlier Excel versions.

Although SUMPRODUCT works with arrays, it does not require using the array shortcut. You compete a SUMPRODUCT formula in a usual way by pressing the Enter key.

Notes:

  • All arrays in a SUMPRODUCT formula must have the same number of rows and columns, otherwise you get the #VALUE! error.
  • If any array argument contains non-numeric values, they will be treated as zeros.
  • If an array is a logical test, it results in TRUE and FALSE values. In most cases, you'd need to convert them to 1 and 0 by using the double unary operator (--) . Please see the SUMPRODUCT with multiple criteria example for more details.
  • SUMPRODUCT does not support wildcard characters.

Basic usage of SUMPRODUCT in Excel

To gain a general understanding of how the Excel SUMPRODUCT function works, consider the following example.

Supposing you have quantity in cells A2:A4, prices in cells B2:B4, and you wish to find out the total. If you were doing a school math test, you would multiply the quantity by price for each item, and then add up the subtotals. In Microsoft Excel, you can get the result with a single SUMPRODUCT formula:

=SUMPRODUCT(A2:A4,B2:B4)

The following screenshots shows it in action:
Excel SUMPRODUCT function - basic usage

Here is what's going on under the hood in terms of math:

  • The formula takes the 1st number in the 1st array and multiplies it by the 1st number in the 2nd array, then takes the 2nd number in the 1st array and multiplies it by the 2nd number in the 2nd array, and so on.
  • When all of the array elements are multiplied, the formula adds up the products and returns the sum.

In other words, our SUMPRODUCT formula performs the following mathematical operations:

=A2*B2 + A3*B3 + A4*B4

Just think how much time it could save you if your table contained not 3 rows of data, but 3 hundred or 3 thousand rows!

Tip. If you want to only multiply the numbers in each row without adding up the products, then use one of the formulas to multiply columns in Excel.

How to use SUMPRODUCT in Excel - formula examples

Multiplying two or more ranges together and then summing the products is the simplest and most obvious usage of SUBTOTAL in Excel, though not by far the only one. The real beauty of the Excel SUMPRODUCT function is that it can do far more than its stated purpose. Further on in this tutorial, you will find a handful of formulas that demonstrate more advanced and exciting uses, so please keep reading.

SUMPRODUCT with multiple criteria

Usually in Microsoft Excel, there is more than one way to accomplish the same task. But when it comes to comparing two or more arrays, especially with multiple criteria, SUMPRODUCT is the most effective, if not the only, solution. Well, either SUMPRODUCT or array formula.

Assuming you have a list of items in column A, planned sale figures in column B, and actual sales in column C. Your goal is to find out how many items have made less sales than planned. For this, use one of the following variations of the SUMPRODUCT formula:

=SUMPRODUCT(--(C2:C10<B2:B10))

or

=SUMPRODUCT((C2:C10<B2:B10)*1)

Where C2:C10 are real sales and B2:B10 are planned sales.
The SUMPRODUCT formula with one criterion to compare arrays.

But what if you had more than one condition? Let's say, you want to count how many times Apples performed worse than planned. The solution is to add one more criterion to the SUMPRODUCT formula:

=SUMPRODUCT(--(C2:C10<B2:B10), --(A2:A10="apples"))

Or, you can use the following syntax:

=SUMPRODUCT((C2:C10<B2:B10)*(A2:A10="apples"))
The SUMPRODUCT formula with multiple criteria to compare arrays.

And now, let's take a minute and understand what the above formulas are actually doing. I believe it is a worthy time investment because many other SUMPRODUCT formulas work with the same logic.

How SUMPRODUCT formula with one condition works

For starters, let's break down a simpler formula that compares numbers in 2 columns row-by-row, and tells us how many times column C is less than column B:

=SUMPRODUCT(--(C2:C10<B2:B10))

If you select the portion (C2:C10<B2:B10) in the formula bar, and press F9 to view the underlying values, you will see the following array:
View the values behind an array

What we have here is an array of Boolean values TRUE and FALSE, where TRUE means the specified condition is met (i.e. a value in column C is less than a value in column B in the same row), and FALSE signifies the condition is not met.

The double negative (--), which is technically called the double unary operator, coerces TRUE and FALSE into ones and zeros: {0;1;0;0;1;0;1;0;0}.

Another way to convert the logical values into the numeric values is multiple the array by 1:

=SUMPRODUCT((C2:C10<B2:B10)*1)

Either way, since there is just one array in the SUMPRODUCT formula, it simply adds up 1's in the resulting array and we get the desired count. Easy, isn't it?
This is how a SUMPRODUCT formula with one condition works.

How SUMPRODUCT formula with multiple conditions works

When an Excel SUMPRODUCT formula contains two or more arrays, it multiplies the elements of all the arrays, and then adds up the results.

As you may remember, we used the following formulas to find out how many times the number of real sales (column C) was less than planned sales (column B) for Apples (column A):

=SUMPRODUCT(--(C2:C10<B2:B10), --(A2:A10="apples"))

or

=SUMPRODUCT((C2:C10<B2:B10)*(A2:A10="apples"))

The only tech difference between the formulas is the method of coercing TRUE and FALSE into 1 and 0 - by using the double unary or multiplication operation. As the result, we get two arrays of ones and zeros:
The values behind two arrays

The multiplication operation performed by SUMPRODUCT joins them into a single array. And since multiplying by zero always gives zero, 1 appears only when both conditions are met, and consequently only those rows are counted:
This is how a SUMPRODUCT formula with multiple conditions works.

Conditionally count / sum / average cells with multiple criteria

In Excel 2003 and older versions that did not have the so-called IFs functions, one of the most common uses of the SUMPRODUCT function was to conditionally sum or count cells with multiple criteria. Beginning with Excel 2007, Microsoft introduced a series of functions specially designed for such tasks - SUMIFS, COUNTIFS and AVERAGEIFS.

But even in the modern versions of Excel, a SUMPRODUCT formula could be a worthy alternative, for example, to conditionally sum and count cells with the OR logic. Below you will find a few formula examples that demonstrate this ability in action.

1. SUMPRODUCT formula with AND logic

Supposing you have the following dataset, where column A lists the regions, column B - items and column C - sales figures:
Source data

What you want is get the count, sum and average of Apples sales for the North region.

In Excel 2007 and higher, the task can be easily accomplished by using a SUMIFS, COUNTIFS and AVERAGEIFS formula. If you are not looking for easy ways, or if you are still using Excel 2003 or older, you can get the desired result with SUMPRODUCT.

  • To count Apples sales for North:=SUMPRODUCT(--(A2:A12="north"), --(B2:B12="apples"))

    or

    =SUMPRODUCT((A2:A12="north")*(B2:B12="apples"))

  • To sum Apples sales for North:=SUMPRODUCT(--(A2:A12="north"), --(B2:B12="apples"), C2:C12)

    or

    =SUMPRODUCT((A2:A12="north")*(B2:B12="apples")*C2:C12)

  • To average Apples sales for North:To calculate the average, we simply divide Sum by Count like this:

    =SUMPRODUCT(--(A2:A12="north"), --(B2:B12="apples"), C2:C12) / SUMPRODUCT( --(A2:A12="north"), --(B2:B12="apples"))

To add more flexibility to your SUMPRODUCT formulas, you can specify the desired Region and Item in separate cells, and then reference those cells in your formula like shown in the screenshot below:
SUMPRODUCT formulas with AND logic to conditionally count, sum and average cells

How SUMPRODUCT formula for conditional sum works

From the previous example, you already know how the Excel SUMPRODUCT formula counts cells with multiple conditions. If you understand that, it will be very easy for you to comprehend the sum logic.

Let me remind you that we used the following formula to sum Apples sales in the North region:

=SUMPRODUCT(--(A2:A12="north"), --(B2:B12="apples"), C2:C12)

An intermediate result of the above formula are the following 3 arrays:
An intermediate result of the SUMPRODUCT formula for conditional sum

  • In the 1st array, 1 stands for North, and 0 for any other region.
  • In the 2nd array, 1 stands for Apples, and 0 for any other item.
  • The 3rd array contains the sales numbers exactly as they appear in cells C2:C12.

Remembering that multiplying by 0 always gives zero, and multiplying by 1 gives the same number, we get the final array consisting of the sales numbers and zeros - a sales number appears only if the first two arrays have 1 in the same position, i.e. both of the specified conditions are met; zero otherwise:
How the SUMPRODUCT formula for conditional sum works

Adding up the numbers in the above array delivers the desired result - the total of the Apples sales in the North region.

Example 2. SUMPRODUCT formula with OR logic

To conditionally sum or count cells with the OR logic, use the plus symbol (+) in between the arrays.

In Excel SUMPRODUCT formulas, as well as in array formulas, the plus symbol acts like the OR operator that instructs Excel to return TRUE if ANY of the conditions in a given expression evaluates to TRUE.

For example, to get the count of all Apples and Lemons sales regardless of the region, use this formula:

=SUMPRODUCT((B2:B12="apples")+(B2:B12="lemons"))

Translated into plain English, the formula reads as follows: Count cells if B2:B12="apples" OR B2:B12="lemons".

To sum Apples and Lemons sales, add one more argument containing the Sales range:

=SUMPRODUCT((B2:B12="apples")+(B2:B12="lemons"), C2:C12)

The following screenshot shows a similar formula in action:
SUMPRODUCT formulas with OR logic to conditionally count and sum cells

Example 3. SUMPRODUCT formula with AND as well as OR logic

In many situations, you might need to conditionally count or sum cells with AND logic and OR logic at a time. Even in the latest versions of Excel, the IFs series of functions is not capable of that.

One of the possible solutions is combining two or more functions SUMIFS + SUMIFS or COUNTIFS + COUNTIFS.

Another way is using the Excel SUMPRODUCT function where:

  • Asterisk (*) is used as the AND operator.
  • Plus symbol (+) is used as the OR operator.

To make things easier to understand, consider the following examples.

To count how many times Apples and Lemons were sold in the North region, make a formula with the following logic:

=Count If ((Region="north") AND ((Item="Apples") OR (Item="Lemons")))

Upon applying the appropriate SUMPRODUCT syntax, the formula takes the following shape:

=SUMPRODUCT((A2:A12="north")*((B2:B12="apples")+(B2:B12="lemons")))

To sum Apples and Lemons sales in the North region, take the above formula and add the Sales array with the AND logic:

=SUMPRODUCT((A2:A12="north")*((B2:B12="apples")+(B2:B12="lemons"))*C2:C12)

To make the formulas a bit more compact, you can type the variables in separate cells - Region in F1 and Items in F2 and H2 - and refer to those cells in your formula:
SUMPRODUCT formula with AND as well as OR logic to conditionally sum cells

SUMPRODUCT formula for weighted average

In one of the previous examples, we discussed a SUMPRODUCT formula for conditional average. Another common usage of SUMPRODUCT in Excel is calculating a weighted average where each value is assigned a certain weight.

The generic SUMPRODUCT weighted average formula is as follows:

SUMPRODUCT(values, weights) / SUM(weights)

Assuming that values are in cells B2:B7 and weights are in cell C2:C7, the weighted average SUMPRODUCT formula will look like this:

=SUMPRODUCT(B2:B7,C2:C7)/SUM(C2:C7)
SUMPRODUCT formula for weighted average

I believe at this point you won't have any difficulties with understanding the formula logic. If someone needs a detailed explanation, please check out the following tutorial: Calculating weighted average in Excel.

SUMPRODUCT as alternative to array formulas

Even if you are reading this article for informational purposes and the details are likely to fade away in your memory, remember just one key point - the Excel SUMPRODUCT function deals with arrays. And because SUMPRODUCT offers much of the power of array formulas, it can become an easy-to-use replacement for them.

What advantages does this gives to you? Basically, you will be able to manage your formulas an easy way without having to press Ctrl + Shift + Enter every time you are entering a new or editing an existing array formula.

As an example, we can take a simple array formula that counts all characters in a given range:

{=SUM(LEN(range))}

and turn it into a regular formula:

=SUMPRODUCT(LEN(range))

SUMPRODUCT as alternative to array formulas

For practice, you can take these Excel array formulas and try to re-write then using the SUMPRODUCT function.

Excel SUMPRODUCT - advanced formula examples

Now that you know the syntax and logic of the SUMPRODUCT function in Excel, you may want to learn more sophisticated and more powerful formulas where SUMPRODUCT is used in liaison with other Excel functions.

Practice workbook for download

Excel SUMPRODUCT examples (.xlsx file)

245 comments

  1. how can I use this to work over multiple sheets??

  2. Good information. Took little bit to understand but once understood it went with flying colors.
    Important finding is one has to multiply the condition to both sum product columns and it works.
    Thanks for posting such detailed information.

  3. Is it possible to use sumproduct to return results based on two different inputs?

    A1 = "Month:" B1 = Input
    A2 = Input B2 =Output

    A3 = Animals
    A4:L4 = Month Names
    A5:L5 = Monetary Value

    So Basically I enter the Month I want values from in B1
    And in A2 I enter the Category, in this case Animals, and in B2 I get the value associated with the lookup from Selecting Animals Feb..

    Is this possible?

  4. Hi
    How can I do the product sum of data where one of the two factors to be multiplied is the difference between two other numbers in separate columns. Is it possible to do this without creating a new column with the difference in the numbers, instead incorporating this calculation in the sumproduct formula?
    Peter

  5. Hi, I a m looking for a formula to resolve the below issue. I have unique Employee ID with duplicate Leaves. I want to highlight duplicate or overlapped leaves (start Date and End Date) under 'My Remark' column.
    Appreciate your assistance.

    ID# Start Date End Date My Remark
    166 04-Sep-17 08-Sep-17 Duplicate Leave
    166 04-Sep-17 04-Sep-17 Duplicate Leave
    166 03-Sep-17 05-Sep-17 Duplicate Leave
    236 01-Sep-17 01-Sep-17 Duplicate Leave
    236 01-Sep-17 01-Sep-17 Duplicate Leave
    243 30-Nov-17 30-Dec-17 Duplicate Leave
    243 01-Dec-17 10-Dec-17 Duplicate Leave
    252 01-Dec-17 10-Dec-17 No Duplicate
    252 01-Nov-17 10-Nov-17 No Duplicate

  6. Hi: I'm wondering if I can use Sumproduct for two sets of arrays? here is what I want to do but it is not recognizine the "+". I am getting only the result for the first array:

    =SUMPRODUCT(--('Pivot RI'!$B:$B=Summary!$A6),--('Pivot RI'!$A:$A=Summary!H$1),--('Pivot RI'!$F:$F=Summary!$B8),'Pivot RI'!$H:$H)+SUMPRODUCT(--('Pivot NV'!G:G=Summary!$A7),--('Pivot NV'!F:F=Summary!H$1),--('Pivot NV'!$F:$F=Summary!$B8),'Pivot NV'!$H:$H)

    So can I not add the information from two seperate data sheets?

    Thank you so much!!

  7. Using COUNTIFS and Logical OR
    For the equation below:
    COUNTIFS($D2:$D$5590,1,$A$2:$A$5590,1008,$B$2:$B$5590,"LINE", $C2:$C$5590, {100,110,120,140,”WAAP”}),
    How can I use the last part to count if it is 100 or 110 or 120 ….

    Maybe the answer is SUMPRODUCT, but it didn't work. Could you please advise. Thank you

  8. I have an interesting problem I cant figure out! I have a file which might make it easier but I will try to explain.

    I have 4 worksheets in one workbook. Datasheet, Homeloans, YR2, Table.

    On Datasheet in M2 I have a Date formatted as d-mmm-yy

    On Homeloans I have Dates from A1:L1 which are derived from the date on Datasheet =DATE(YEAR(Datasheet!$M$2),MONTH(Datasheet!$M$2)+0,1) that progress up to =DATE(YEAR(Datasheet!$M$2),MONTH(Datasheet!$M$2)+11,1) in L1
    In A2:L2 I have values entered

    On YR2 I have the same setup. The date system is setup to look like a fiscal year instead of a calendar year.

    On the Table sheet from B1:Y1 I have dates. B1 uses the formula =IF(Datasheet!M2"",TEXT(Datasheet!M2,"d-mmm-yy"),"Jan") B2 uses =IF(OR(B$1="",B$1=""),"",TEXT(EDATE(B$1,1),"d-mmm-yy")) and is propagated to Y1.

    In B2:Y2 I am using this formula =SUMPRODUCT(--(TEXT(Homeloans!$A$1:$L$1,"d-mmm-yy")=B$1),Homeloans!$A$2:$L$2) with it changing respectively to Y2

    This is the tricky part.

    On Table, Cell C18 I have a data validation list setup to select a year number

    On Table, E18 I have formula =SUMPRODUCT(--(RIGHT(TEXT($B$1:$Y$1,"d-mmm-yy"),1)+0=$C$18),$B$2:$Y$2)

    Here is the problem.

    If I set the date on Datasheet to 1/11/2011 and I select year one on C18 on the Table sheet, I get the correct sum on E18.

    If I change the date on Datasheet to 1/11/2012 it flips the value in E18 to zero. This is the weird part. If I change the value in C18 to 2 for second year, then it gives me the correct sum. So I played with the formula
    =SUMPRODUCT(--(RIGHT(TEXT($B$1:$Y$1,"d-mmm-yy"),1)+0=$C$18),$B$2:$Y$2) and found that if I change the highlighted part to +-1 then select year one again, it gives me the correct sum.

    It sort of does what I need it to do but the problem is for every date set I will have to go in and change that value up and down the number line according to the date on Datasheet and that just isnt going to work. It need to be dynamic and pull values based on the year the values show up in.

    So if a payment is entered for example on 1/11/11 as the first payment and the second payment on 1/12/11, and I want to know the totals for the first year of the loan, it should only give me that value in E18.

    Any help in resolving this would be greatly appreciated. Im running out of forehead to bang against the wall!

    Regards,
    D

    • Hello,

      For me to understand the problem better, please send me a small sample workbook with your source data and the result you expect to get to support@ablebits.com.
      Please also don't forget to include the link to this comment into your email.

      I'll look into your task and try to help.

  9. VALUE 100 500 600 700 800 900
    TOTAL QTY.
    RAM 10 1 2 3 4
    MOHAN 24 2 3 1 6 7 5
    SOHAN 31 2 3 4 6 7 9
    VIMAL 28 1 1 5 6 7 8

    need to value of each person wise

  10. Hi, thank you so much, this page was a great help. I have one case that I need some help. I noticed that when I use sumproduct with an OR connection, the values provided are not TRUE or FALSE (e.g. TRUE,FALSE+TRUE,FALSE resulting in {2,0}) How can I have a TRUE/FALSE output?
    I want to know in how many rows either or both of the conditions appear, and not the count of every occurance.
    Thank you for your help!

    • hello, I found a solution, the resulting array e.g. {2,0} can be adapted like this: --{2,0}>0 to result in {1,0}

  11. =SUMPRODUCT(--('Excel - Full Data'!$D$4:$D$2100="WCCI"),('Excel - Full Data'!$K$4:$K$2100>0)*('Excel - Full Data'!$K$4:$K$2100<5000)*('Excel - Full Data'!$K$4:$K$2100))

    Am I able to add an Additional parameter which includes "WCCI - TS" to the "WCCI" for $D$4:$D$$2100 range?

    Any help would be greatly appreciated

    • Hello,

      If I understand your task correctly, please try the following formula:

      =SUMPRODUCT((('Excel - Full Data'!$D$4:$D$2100="WCCI")+('Excel - Full Data'!$D$4:$D$2100="WCCI - TS")),('Excel - Full Data'!$K$4:$K$2100>0)*('Excel - Full Data'!$K$4:$K$2100<5000)*('Excel - Full Data'!$K$4:$K$2100))

      Hope this will work for you

  12. Finding the double unary operator has been so helpful! I currently have very large files that I am creating tables for and can't get this equation to work. I am wondering if there is a row limit for the formula, since this is the largest list I am working with.

    SUMPRODUCT(--('Master List'!$B$2:$B$11091=$A$1),--('Master List'!$F$2:$F$11091""),--(MONTH('Master List'!$F$2:$F$11091)='Data Table - DO NOT DELETE'!F$3),--(YEAR('Master List'!$F$2:$F$11091)='Data Table - DO NOT DELETE'!F$2))

    Note, the only part of this equation that breaks when providing an answer is the month and year. I do have a formula in column F, however this shouldn't make a difference.

  13. A big "Thank you" for helping me out in understanding Sumproduct function

  14. This has been super helpful! My tables have been more efficient since finding double unary operator. The only challenge is that there is not a lot of help to troubleshoot. I have a simple equation that won't calculate. When I look at the functional arguments, I don't see any errors on my arrays.

    My equation: SUMPRODUCT(--('Data Input'!B4:B37='All-up Burndown Chart'!A2),'Data Input'!F3:F37)

    If column B (which is a list of buildings) equals a building number identified in cell A2, then sum the fields in column F.

    Any thoughts on why I'm not getting an output?

  15. Please help me to sum below 2 array...

    I want to add particular value of column 4 in column 2 if condition of column 1&2 satisfy, example I want to add Jan month value to each date of Jan month.

    02-01-2017 414.748 JAN 312.6446
    04-01-2017 476.886 FEB 796.09325
    05-01-2017 409.566 MARCH 358.3840417
    06-01-2017 398.519 APRIL 241.6108077
    01-02-2017 1051.862 MAY 94.96810345
    03-02-2017 790.097 JULY 9.945451613
    04-02-2017 563.685
    05-02-2017 463.103
    09-03-2017 855.292
    10-03-2017 957.937
    11-03-2017 1056.677
    12-03-2017 1077.678
    13-03-2017 1569.847

  16. Hi Ma'am I just want to say thank you. You are so kind and brilliant, I wish I can be like you someday. Thank you so much. You are an inspiration to me, please continue helping people like me. ^_^

  17. kindly tell me how to get the total of two items through Sumproduct formula...

  18. Hi
    I have a table of profit and loss information running for a whole year but I want to set up a formula that will calculate the year to date position. eg I type in June and the financial info say revenue from January to June is added together. Tried initial using an array and could do this with a basic =if function but there must be a better way.
    thanks Paul

  19. Hi Guys,

    I need some help in excel formula
    I have some data with city name and numbers so just i wanted to identify the only unique values using only formula.

    Data is like that

    A B
    City Number
    A 123
    B 456
    A 678
    A 123

    Thanks in advance!

    • Hello, Amol,

      To highlight the unique values, please select the column with the data, then on the Home tab, in the Styles group, click Conditional Formatting > Highlight Cells Rules > Duplicate Values. In the next pop-up window select Unique, choose the colour and press OK.

      You can learn more on how to apply conditional formatting for uniques or duplicates in this article.

      Please note that if you want to use the formulas, the values will be either simply counted or transferred to another columns. If this is what you need, please specify.

  20. Used =sumproduct(1/countif(array1,array2)) to count unique values in a column with duplicates but once table is filtered the answer doesnt change.

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)