Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Selective Summing.

Selective Summing

Written by Allen Wyatt (last updated December 1, 2018)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


3

Excel contains a built-in function that allows you to easily specify which values should be summed from a column. This function, SUMIF, is used in the following manner:

=SUMIF(Testrange,Test,Sumrange)

In this usage, SUMIF uses three arguments. The first is the range of cells to be tested, the second is the test to use, and the third is the cells from which the sums are to be pulled. For instance, let's say that the cells in B2 through B27 contained days of the week (Monday, Tuesday, etc.), and that cells C2 through C27 contained the gross sales generated on those days. If you wanted to only get a sum for the sales on Mondays, you could use the following formula, perhaps in cell C28:

=SUMIF(B2:B27,"Monday",C2:C27)

This examines B2 through B27 and checks if the cell contains the text "Monday." If it does, then the corresponding cell is selected from C2 through C27 and added to the sum.

If you wanted to quickly pull sales totals for different days, you could modify the above scenario just a bit. All you would need to do is place the day on which you want to sum in cell B28. Then, in cell C28 you would place the following formula:

=SUMIF(B2:B27,B28,C2:C27)

Now the test for SUMIF is taken from cell B28. Thus, if B28 contains "Monday," then the sum will reflect the total of Monday's sales. If it contains "Wednesday," then Wednesday's sales will be summed, and so forth.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7013) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Selective Summing.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Always Printing Drawing Objects

Add a bunch of drawing objects to your document, and you may wonder how to make sure they all appear on a printout. How ...

Discover More

Delivery Address Won't Print on Envelopes

Word includes a feature that allows you to easily create and print envelopes, based on the addresses you insert in your ...

Discover More

Getting a File Name

Does your macro need to allow the user to specify a particular file name that should be used by the macro? Here's a quick ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Understanding Operators

At the heart of working with Excel is the process of creating formulas that calculate results based on information within ...

Discover More

Combining Cell Contents

Excel allows you to easily combine text together. Interestingly, it provides two ways you can perform such combinations. ...

Discover More

How Operators are Evaluated

Operators are used in formulas to instruct Excel what to do to arrive at a result. Not all operators are evaluated in the ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 9 + 4?

2018-12-03 22:17:20

Roy

Actually, it does "fail" in most people's minds, in that it will give an unexpected (and certainly undesired) result if the range you are testing differs in size from the range you want to sum over.

For instance, =SUMIF(J10:J13,">13",H5:h6) might only meet the condition in J13 which is its 4th element. It will pick the 4th element of the range of interest, H5:H6. Umm... That would be H8. And it is.

I've never seen a good explanation for that, though it logically extends from some ways one might (poorly) write the function in code. It certainly does let one use ranges that are not "relative" to each other, J10:J13 lying across, left/right, from H10:H13, for example and the 10's being compared, etc. But... that would have been achieved just by taking what people put in literally, instead of "interpreting" it. So... no explanation.

Simply using "H5" would give the same result as above. I guess if one always built the test range using OFFSET, etc. to calculate its end based upon the range of summing interest... Lordy though, that's putting the cart before a LOT of horses.

Never know though, that might be a useful thing for some trick providing what Excel doesn't see fit to program in.

But it isn't "incorrect" - just surprising and always pretty undesired.


2018-12-01 06:14:32

Alex B

I totally agree with Col.
In addition to what Col said, SumIf also has a bug in it and instead of giving you an error message if you select disparate ranges for your sum range and criteria range, it will give you an incorrect result.
SumIfs under the same conditions gives you #Value making you aware of the error.


2018-12-01 05:35:56

Col Delane

Since the introduction of the multiple criteria SUMIFS function in Excel 2007, no Excel user should ever again use the single criterion SUMIF function. Whilst SUMIFS can handle a single criterion just like SUMIF, the flexibility to easily add criteria should the need arise (which cannot be done with SUMIF) is why the latter should no longer be used.

The syntax of the SUMIFS function is also more logical than SUMIF as the sum_range argument is listed first, with each set of criteria_range and criteria following, viz;
=SUMIFS( sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ... )


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.