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

Using AutoSave in Excel

It is a good precaution to periodically save your work. That way, if you have an unforeseen problem with your computer, ...

Discover More

Recording a Data Entry Time

When entering information in a worksheet, it is common to also note a date or time corresponding to the entry. There are ...

Discover More

Passing Custom Caption Labels from a Template to a Document Based on the Template

Caption labels can be useful when you are adding document elements such as tables and figures. Word allows you to create ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Strange Value Results in a Cell

When Excel performs a calculation, the results you see in an unformatted cell may cause a bit of concern. This tip ...

Discover More

Converting from Relative to Absolute

Addresses used in a formula can be either relative or absolute. If you need to switch between the two types of ...

Discover More

Listing Combinations

You can easily use the COMBIN worksheet function to determine the number of combinations that can be made from a given ...

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 six more than 3?

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.