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:
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:
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.
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"))
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:
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?
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 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:
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:
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:
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:
- 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:
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:
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 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:
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)
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:
and turn it into a regular formula:
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
funny site not accept formulas in text..
SUMPRODUCT((F9lessthan{0.01,1,5})
ASTERISK
parenthesisMIN(M9:N9)greaterthan{1,3,9}))
Nice workaround to assist with a formula, Dave!
Thanks for your persistence! :)
geez 1 more time
=SUMPRODUCT((F9{1,3,9}))
=SUMPRODUCT
((F9{1,3,9}))
oh well, delete something. my post got chopped.
=SUMPRODUCT((F9{1,3,9}))
hi, i don't think i saw an example for multiple levels. i think this will work. thanks.
=SUMPRODUCT((F9{1,3,9}))
Hi there,
I'm using the following formula, but I want the formula to choose the same text as a cell (B20), is there a way the formula can be adapted?
=SUMPRODUCT(--(B68:B109="B20"),--(N68:N109))
B20 is an individual's name, so will look different for the next cell - currently having to manually enter in individual names.
I've never been good with sumproduct, and I think it's the answer to my problem but I can't get it to work! I want to add up everything with an account number that begins with 7, easy enough except that there are spaces in front of the account and the number of spaces is always different. So I want to basically do SUMPRODUCT(LEFT(TRIM($A:$A),1)="7"),$B:$B). The amounts are in Column B and the criteria is in Column A. I can't get this to work for the life of me!!
=SUMPRODUCT((LEFT(TRIM($A:$A),1)="7")*1,$B:$B)
Hi Concern,
Thanks a lot for made a good opportunity to know about excel. Very helpful article.
Hi,
I have 3 sheets namely: Data, Assumption, Summary
In assumption sheet, you can see criteria 1 and corresponding criteria 2.
In Data Sheet, you can see criteria 2 and amount.
In summary Sheet, I needed Criteria 1 and amount.
Usually, I have to lookup criteria 1 from assumption and put it in data sheet. But I am not allowed to modify data sheet.
Or, =SUM(SUMIF(Data Sheet criteria 1 range,{"criteria 1,criteria 1,criteria 1,criteria 1"},Data sheet sum range)). But when I require to change assumptions, I have to update formulas.
My problem is:
1) I should not modify data sheet
2) I needed my summary to be updated for any changes made in assumptions
Please feel free to share your ideas.
I have many employees in my spread sheet , am just giving some sample date here . I have to find the min and max time for each employee and for each date . How can I do that.
Employee date time
e1 1-Jan-13 8:10
e1 2-Jan-13 8:00
e1 2-Jan-13 9:00
e1 2-Jan-13 10:00
e1 2-Jan-13 11:00
e1 1-Jan-13 16:00
E2 2-Jan-13 8:10
E2 2-Jan-13 8:00
E2 2-Jan-13 9:00
E2 2-Jan-13 10:00
E2 2-Jan-13 11:00
E2 1-Jan-13 17:00
Employee ID is in range $A$1:$A$12, date is in range $B$1:$B$12 and time is in range $C$1:$C$12.
Look up Employee ID is e2 and look up date is f2.
max time:=SUMPRODUCT(MAX((($A$1:$A$12=E2)*1)*(($B$1:$B$12=F2)*1)*$C$1:$C$12))
min time:=SUMPRODUCT(MIN(((($A$1:$A$12E2)*100)+(($A$1:$A$12=E2)*1))*((($B$1:$B$12F2)*100)+(($B$1:$B$12=F2)*1))*$C$1:$C$12))
Hello,
I'm having an issue adding multiple numbers in one cell, based on which side of the / they are on. The formula to add two different numbers separated by a / (ex 5/7) is =SUMPRODUCT(--LEFT(AA8:AA11,FIND("/",AA8:AA11)-1))&"/"&SUMPRODUCT(--REPLACE(AA8:AA11,1,FIND("/",AA8:AA11),0))
But what about if I want to change it to 3 values, like 7/4/10. How would this affect the formula?
Thanks!
I'd like to sumproduct the two column,that the value are negative.
please help me.
Hello all,
I am trying to write a formula for the following conditions in excel.
Penalties(Days) Penalty per violation
1-14 $1,000
15-30 $2,000
31-60 $3,000
61-180 $4,000
>180 $5,000
Please help me to write a formula to calculate total penalties incurred based on the number of days of delay.
Thanks
Rama
Dear Rama,
Try the function VLOOKUP:
1) make up a simple reference table of two columns - Days and Penalty;
2) in the Days column insert a number that is equal to the right border of each range plus 1:
1 1000
15 2000
31 3000
61 4000
181 5000
3) convert your reference table into a named range, for example, Days_to_Penalty;
4) use VLOOKUP(number_of_days; Days_to_Penalty; 2; 1);
5) it's the last argument (1) that makes VLOOKUP search NOT the exact values.
Hi,
Is it possible to use conditional weighted average for sales matrixes? Lets say I have few products with different sales amounts and different prices, and want to get conditional weighted average for price based on sales amount and product type.
thanks.
thnx
Hi there,
thank you for the web information about excel.
I have a question, how to use SUMPRODUCT to sum range of value which is positive or negtive.
thank you
Yao Yao
I have this formula in cell F3 in my table
=SUMPRODUCT((TEXT($I:$I,"mm-yyyy")="01-2016")*1) and it works great
I would like to change the ="01-2016")*1)to reference cells in the next column so F3 would reference E3, F4 - E4 and so on but I can not seem to do it can you please help
Try this;
=SUMPRODUCT(--($I:$I=G3))
G3 is the ref cell that brings dynamical selection to the sumproduct formula
Hi,
I am having a problem how to work out a formula to calculate the sum of the smallest three values in a range. However the range is on alternate columns
for example
pos cat pos cat pos cat pos cat pos cat pos cat pos cat
4 2 6 4 1 1 3 3 10 10 - - - -
i wish to total the best three results in the pos columns (ignoring the blank columns - )
my result should be :
all pos results are 4,6,1,3,10 - sum of best three results(smallest) = 4+1+3 = 8
is there a formula which could perform this
many thanks for any help
Thank you for this article -- it's very helpful. I'm wondering if you could give me some advice on the following:
I’m trying to create a spreadsheet that will track staff time-off. The formulas are getting a bit complicated because they are totaling from 5 separate “hours absent” columns (one for each day of the work week) and 5 corresponding “type of time off” columns. Columns headers are in row 9. The sheet is set up so that supervisors can select a particular week (column A), an employee (column B), and then the hours absent on Monday of that week (column C) and type of time off taken on that day, e.g., PTO, vacation, jury duty, etc. (column D). Columns C and D are then basically repeated through Column L to account for each day of the week through Friday.
In the section that totals the time-off for each employee, I want a total time taken for the year, as well as a breakdown showing the total of each type of time off taken by that employee. I’ve managed the total time taken with the following:
=SUMPRODUCT(($B$10:$B$188=”Annie”)*($C$9:$L$9=”Hours Absent”),$C$10:$L$188)
However, I’m struggling with the formula for the disaggregated data. Here is what I have at the moment to disaggregate only the PTO-type of time off:
=SUMPRODUCT(($B$10:$B$188=”Annie”)*($C$9:$L$9=”Hours Absent”)*((D10:D188=”PTO”)+(F10:F188=”PTO”)+(H10:H188=”PTO”)+(J10:J188=”PTO”)+(L10:L188=”PTO”)>0),$C$10:$L$188)
It almost works, but only excludes non-PTO hours from the Monday column (column C). So, it is (correctly) NOT including Annie’s vacation-type time on Monday, but IS (incorrectly) including her vacation-type time on Tuesday through Friday.
I’m hoping I’m missing something simple and you can set me on the right path! I started out thinking this could all be easily solved with a pivot table, but can’t seem to make that work either…
Any advice would be greatly appreciated!
Amy
Hello Amy,
To make things easier for us to understand, can you please send a sample workbook to support@ablebits.com, or upload it to Excel Online and post a link here.
I want to transfer date to another sheet automatically to specific sheet with specific data
I fill all data in sheet 1 and split this data to others sheet 1, sheet 2 , sheet 3 ....
All i need is to transfer date because i recall the others data from sheet 1by using array function SUMPRODUCT, SUMIFS.
My header including,
Date Tag Fueld Hour/Km
I use SUMPRODUCT function to recall the Tag, Fueld and Hour/Km from main sheet 1 by manual filling the date.
Please help me on this situation or would be appreciate for another way.
Sorry for my English!
Thanks in advanced,
thuraz
hi Svetlana,
thank you for sharing your experince of excel.
thats great.
one of the other usage of sumproduct function is
to limit user to enter data in column A only using character (without contain number);
1-select column A
enter this formula in the costum section at data validation.
=sumproduct(--isnumber(--mid(a1;row(indirect("1:"&len(A1)));1)))=0