What is Excel SUMPRODUCT formula and how to use it?

Posted on November 10th, 2009 in Featured , Learn Excel - 31 comments

Today we will learn a new and exciting excel formula – the all powerful SUMPRODUCT.

At the outset SUMPRODUCT formula may not seem like all that useful. But once you understand how excel works with  lists (or arrays) of data, the SUMPRODUCT’s relevance becomes crystal clear.

SUMPRODUCT formula – syntax and usage

Excel SUMPRODUCT formula - tutorialThe sum-product formula syntax is very simple. It takes 1 or more arrays of numbers and gets the sum of products of corresponding numbers.

The syntax is =SUMPRODUCT (list 1, list 2 ...)

Excel SUMPRODUCT formula - examplesSo, for ex: if you have data like {2,3,4} in one list and {5,10,20} in another list, and if you apply SUMPRODUCT, you will get 120 (because 2*5 + 3*10 + 4*20 is 120).

At this point it might seem like an almost useless function. But all that will change in the next 2 minutes, keep reading.

SUMPRODUCT and Arrays

Lets say you have a list of sales data with columns Name, Region, Product and Sales. Now, you want to know how many units the sales person named “Luke” sold. This is simple, you will write a SUMIF formula [examples] and use the Name column as “criteria range” and Sales column as “sum range”.

But, wait a second, you want to find how many units sales person “Luke” sold in the region “west”.

Hmm…. we have 2 options,

Actually, there is a hidden third option, use SUMPRODUCT.

That is right, my friend, we can use SUMPRODUCT to do just this (and much more).

Using SUMPRODUCT as an array formula

Assuming, the data is in range A1:D10, with Name in column A, Region in B, Product in C and Sales in D, the SUMPRODUCT formula is,

=SUMPRODUCT(--(A1:A10="Luke Skywalker"),--(B1:B10="West"),D1:D10)

Okay, lets take a minute and try to understand WTF (what the formula) is doing.

  • The portion --(A1:A10="Luke Skywalker")is looking for Luke Skywalker across planetary systems in all universes ;) It is going to give us a bunch of ONEs and ZEROs, one if the cell has Luke, Zero if the cell has something else.
  • The portion --(B1:B10="West")is doing the same, but gets 1s when the value is “West”.
  • The portion D1:D10 is just returning all the sales figures.
  • When you put everything together and multiply, it just works. Why? That is your home work to figure out.

Excel SUMPRODUCT formula example and explanation

Share your SUMPRODUCT formula Tips & Tricks

SUMPRODUCT formula can do much more once you understand how it works. This post is meant to open the door for you. Go ahead and explore the possibilities, then come back and share your tips with us.

Recommended Reading

I suggest reading the excel array formula examples, sumif with multiple conditions and other excel formula tutorials.

This post is part of our spreadcheats series

| More
Excel School - Online Excel Training Program

Comments
Cyril Z. November 10, 2009

Nice explanation Chandoo, I love it. It’s “almost” crystal clear for me.

Can you explain the use of — before the test ?

Chandoo November 10, 2009

@Cyril .. good point. the double hyphen is converting a list of boolean (true, false) values to ZEROs and ONEs. Each hyphen acts as a negation. When you negate something, excel converts the underlying values to numbers and then reverses the SIGN. So TRUEs become -1s and FALSEs become 0s. The second negation reverses this and leaves just numbers thus allowing sumproduct to actually multiply instead of throwing an error.

Moatasem November 10, 2009

Another alternative for this example is to use SUMIFS function, but it is available only in excel 2007 & 2010

Rakesh November 10, 2009

Nice post Chandoo!!
Is there any limit to the number of arguments we can use with SUMPRODUCT function?

Gerald Higgins November 10, 2009

Chandoo – good explanation. I’m still learning about sumproduct, arrays, and the function of — .

I’d read elsewhere about using — to “coerce” some values – I know what coerce means but I didn’t really understand it in this context. I do understand your explanation though – basically it’s multiplying the results by -1. I tried using – instead of –, and it appears to work just the same, as long as you have an even number of arrays to multiply, as you do in your Luke Skywalker, West example.

kaliman November 10, 2009

Hi all,
I’ve seen the double hyphen (–) in all SUMPRODUCT tips, but haven´t used and so far my formulas seem to work fine (no errors)… any idea when it should really be used?.

Gerald Higgins November 10, 2009

Kaliman – for me, Chandoo’s Luke Skywalker / West example doesn’t work unless I use the double hyphen – -

I’ve just noticed in my earlier post, I had typed 2 hyphens and it came out looking just the same as 1. Apologies if anyone was confused by that :-)
It should have read “…I tried using – instead of – - …”

Brian S November 10, 2009

The double-negative on the TRUE/FALSE result is likely my favorite formula trick, and has always allowed me to stay away from arrays (which I find cumbersome and error-prone).

Chandoo/Excel Gurus, do you believe the SumProduct usage is inherently faster than an array of SumIFs? I’ve read Excel forum threads that assert that the SumProduct performance difference is negligible because Excel was performing array activities behind the scenes, but those threads were a bit old (circa 2002/2003), and I never really bought into it. What has your experience been on the performance question?

Finnur November 10, 2009

Great post. The array part of this post will come in extremely handy at work.

mikii November 10, 2009

sumproduct() is my favourite multiple condition summing formula. but double”-” before the argument was a new thing for me as I usually used syntax like this =sumproduct((array1=”luke”)*(array2=”west”)*array3)
however, sumproduct has one drawback – the array you want to sum must consist only from numericals. even if actual selections wont include cell like “n.a.” (might happen in datasets), sumproduct() will result in an error. find/replace helps just fine ;)

Andy November 10, 2009

Seconding the use of SUMIFS if you have 2007 or higher. I personally find it much more intuitive.

Modeste November 10, 2009

Hi Brian, Hi Shandoo,
for more details and considerations …
here from an Excel Guru :
http://www.xldynamic.com/source/xld.SUMPRODUCT.html

;o)))

Kanti Chiba November 10, 2009

Great explanation Cahndoo,

I have seen the — used often in the SUMPRODUCT formula but not the N() fucntion, is there a reason not to use the N() function?

Sal Paradise November 11, 2009

Excel has trouble doing math with text values. It needs to turn them into numbers first.

Type ‘0 into a cell (mind the quote). This makes a text zero.

Type =A1=0 into another cell, and you will get FALSE as the result.

Type =A1-1 into another cell, and you will get -1

But wait, if it’s not a number, why can it do math?!

Well, Excel forces things to be numbers when you do math on them.

So if you use math in sumproduct, you don’t need the double-minus:
=SUMPRODUCT((A1:A10=”Luke Skywalker”)*B1:B10=”West”)*D1:D10)

When it does the math for this, it will multiply all the zeroes and 1’s and values together, and will always come out with a number.

If you don’t put them in:
=SUMPRODUCT((A1:A10=”Luke Skywalker”),(B1:B10=”West”),D1:D10)

You get 0 instead.

So we need to turn them into numbers first. We can do that a lot of ways. For instance:
=SUMPRODUCT((A1:A10=”Luke Skywalker”)+0,(B1:B10=”West”)+0,D1:D10)

=SUMPRODUCT((A1:A10=”Luke Skywalker”)*1,(B1:B10=”West”)*1,D1:D10)

=SUMPRODUCT(N(A1:A10=”Luke Skywalker”),N(B1:B10=”West”),D1:D10)

But when it comes down to it, the people who are really smart at Excel figured out that Excel is fastest when it uses the unary operator (the ‘-’ sign) twice.

So now people write:
=SUMPRODUCT(–(A1:A10=”Luke Skywalker”),–(B1:B10=”West”),D1:D10)

Feel free, if you have trouble, to use the *1 or +0 or N() if you’d prefer. They will work too.

So, to conclude.

If you use SUMPRODUCT with commas, you need to turn true/false values into numbers first by doing math or by using the N() function.

If you use SUMPRODUCT with multiplication, you’re already doing math so you don’t need it.

Most of the time it’s personal preference (I’m sure that there is a difference in speed in the long run, but most of us will probably never ever know about it).

Yogesh Gupta November 11, 2009

Hello Chandoo

– makes formula confusing for many users and it can be avoided if you replace , with * . The revised formula will be as under
=SUMPRODUCT((A1:A10=”Luke Skywalker”)*(B1:B10=”West”)*(D1:D10))

This formula is giving multiconditional sum and we have used only two conditions. However you can add as many conditions as you like provided the hight of each range is same.

If you remove the last entry with does not have condition attached to it, the formula will do the multiconditional count.

Formula for multiconditional count will be
=SUMPRODUCT((A1:A10=”Luke Skywalker”)*(B1:B10=”West”))

Thanks

Simon November 11, 2009

Does this usage of SUMPRODUCT allow for multiple entries of the search criteria throughout a range?

i’ve always been fond of the SUMPRODUCT((range=criteria)*(range=criteria)) to search for multiple variables: Saves on pesky pivot tables.

Chandoo November 11, 2009

@Moatasem & Brian & Andy

Yes, we can use SUMIFS in the same way. It is a better function, but not backward compatible with earlier versions of excel. That is why I wrote about this first. I will write about SUMIFS , AVERAGEIFS and COUNTIFS in an upcoming article.

@Rakesh…

You are welcome. Yes, There are limitations on SUMPRODUCT – It takes up to 255 arrays. It also slows down considerably once you have too many rows in the arrays (lists). I suggest using pivot tables or manual calculation mode if that happens.

In general, SUMPRODUCTs hold up well even for fairly large data (like few hundreds of rows or even thousands).

@Gerald

it is better to use double hyphen (minus sign) before every array as it lets you add / remove arrays with out worrying about the even-ness of the number of attributes.

@Brian S

“Chandoo/Excel Gurus, do you believe the SumProduct usage is inherently faster than an array of SumIFs? …”

I have not benchmarked SUMPRODUCT against other similar formulas like VLOOKUP, MATCH or Array SUM() formulas. But I have experienced considerable slow down when I have few thousand rows of data, no matter what formula is used. If I am writing the code behind these formulas, I would have used similar logic for all. So I dont see a reason why one formula should be faster / better than other. But I am as intelligent as a cabbage when I am talking about these things.. so…

Here is a request to all.. “if you have benchmarked these formulas, please let us know the results thru comments”

@Modeste … Thanks for the excellent link.

@Kanti Chiba

You can use N() in the same way. N() formula converts the input to number.

@Sal .. awesome explanation. Donut for you.

@Yogesh .. Again, super trick. I agree with * approach. Donut for you as well.

@Simon

You can use Array concepts like + operator to check for multiple conditions. For eg. ((A1:A10=”Luke Skywalker”)+(A1:A10=”Hansolo”)) should check for both Luke and Hansolo in the range A1:A10.

Jeff Weir November 16, 2009

Chandoo my man. I had to multiply some arrays today, and was momentarily scratching my head trying to remember how to do this with array formulas. I took a break, checked out your RSS feed, and whoa…you’ve taken my question right out of my mind and answered it.

I owe you a donut for this, which cancels out the one I earnt the other day. Don’t you just love this weightless, low calorie economy?

Chandoo November 16, 2009

@Jeff, in the donut economy things never cancel out. They just get added up, because donuts are absolute(ly delicious).

Eric Lind November 23, 2009

I seriously wonder how many people-hours you saved with this one post alone Chandoo.

I guess it leaves more time for virtual donuts. :)

Chandoo November 23, 2009

@Eric.. that is so sweet (and not in the heart killing donut sweet way). Thank you :)

Jadam December 15, 2009

I have a sumproduct question!
In my workbook i am working with 2 worksheets: “Hours” & “Variance”.

I am essential developing a variance tool on the variance tab.

I have a list of employees on the hours tab and the rests of the actual hours that they have worked by dated column.

I am trying to write a formula that totals all of the hours for a single employee based on a given date. See example at the end.

These formulas work as a stand alones:

=ADDRESS(MATCH(A10,Hours!$M$621:$M$725,0)+ROWS(Hours!$L$1:$L$620),MATCH($C$2,Hours!$620:$620),4,1,”Hours”)

=SUMPRODUCT(–(Hours!M621:M725=A10)*Hours!$N$621:$BZ$725)

BUT, when I try to combine the two to get the date variability like I want, Excel says my formula contains an error. Here is what the formula looks like:

=SUMPRODUCT(–(Hours!M621:M725=A10)*Hours!$N$621:ADDRESS(MATCH(A10,Hours!$M$621:$M$725,0)+ROWS(Hours!$L$1:$L$620),MATCH($C$2,Hours!$620:$620),4,1,”Hours”))

Doughnuts all around for anyone who can help me on this one! I suspect that I have a syntax issue in my formula but not sure.

Example:

Variance Tab
As of: 11/28/2009

Resource Total hours worked Answer should be
Billy 130
Bob Formula 50
Joe goes 80
An here 90
Jill 160

Hours Tab

Resource 11/14/2009 11/28/2009 12/12/2009
Billy 40 90 30
Bob 30 20 80
Joe 50 30 80
An 80 10 40
Jill 80 80 50

Jadam December 15, 2009

bummer, example data formatted ugly….imagine rows and columns, rows and columns

Chandoo December 16, 2009

@Jadam… I think this is happening because you cannot define a range like a1:Address(xxx), it has to complete range or complete indirect. Why dont you use INDIRECT(”Hours!$N$621:”&ADDRESS(…)) in the sumproduct.

Also make sure the INDIRECT is wrapped in ()s to avoid any confusion.

Modeste December 17, 2009

Hi Chandoo, Hi Jadam

;o))) there is no use of SUMPRODUCT ….

just you have to name some ranges
ResDat =Hours!$B$1:$A$Z1 ( ie for 52 dates)
ResNam =Hours !$A$2:$A$1000 ( ie for 1000 names)

in Variance!B2 put this formula
=SUMIF(WBK1!resDat,”<="&$A$10,INDIRECT("hours!"&ADDRESS(1+MATCH(A2,WBK1!resNam,0),2)&":"&ADDRESS(1+MATCH(A2,WBK1!resNam,0),52)))

and pull it down as many time as ressource names
beware :
dateref of calculation is absolute $A$10
current ressource name is relative : A2

WBK1 is actual Workbook.name

HTH
;o)))

Hui... January 11, 2010

Supposedly — is slightly faster than any other way of converting the logicals to numbers.

My preference is to use =SUMPRODUCT(1*(A1:A10… instead of =SUMPRODUCT(–(A1:A10=
As it is easier to read, especially for those not so familiar with formulas.

uktiMike January 20, 2010

Just fallen on this site – already hooked.

Sumproduct is great. I used to struggle to add multipple criteria up in my spreadsheets, and then someone from UtterAccess.com taught me about Sumproduct. I can’t thank that person enough.

Anyway…many articles to catch up on. Keep up the outstanding work.

Daniel Ferry February 2, 2010

Chandoo:

The SUMPRODUCT function is the most versatile in Excel.

It can be used to do multicolumn sorts by array (with no human intervention or VBA required).

It can determine if a number is prime.

It can coerce bitwise operations in integers (i.e. bitwise logical AND, OR, XOR, IMP, EQ, and NOT).

It can be used to supercharge lookup tables with bitmasks.

It can find the dot product of two vectors.

It can do the database calculations you addressed in this post and has the massive advantage over SUMIF and COUNTIF (and the Excel 2007 SUMIFS and COUTNIFS) that it can handle OR clauses in the criteria.

It can replace most any Array-Entered Formula that uses SUM, and is usually about 10% faster.

This list could go on for pages…

I have a very detailed post on my blog:

http://www.excelhero.com/blog/2010/01/the-venerable-sumproduct.html

Regards,

Daniel Ferry
excelhero.com/blog

RSS feed for comments on this post. TrackBack URI

Leave a comment

   Name (required)

   E-mail (required, never displayed)

   URL


If you have a question, please ask in the forums

Recommended Excel, Charting, VBA books