Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 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

by Allen Wyatt
(last updated December 1, 2018)

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 Office 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

Differences in Behavior of Links

Got some active links in your document? Do you want to have them activated when you click on them, or do you want to ...

Discover More

Nudging a Graphic

Want to get a graphic to just the right position on a worksheet? Sometimes the easiest way is to use the arrow keys on ...

Discover More

Displaying File Extensions

File extensions help both you and Windows understand how to work with a particular file. By default these extensions are ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Patterns of Numbers with a Formula

Want to create a sequential pattern using formulas? It's easy to do if you take a look at how your data repeats. This tip ...

Discover More

Ignoring Case in a Comparison

Do you want Excel to take the case of your text into account when it does comparisons in a formula? The IF statement ...

Discover More

Separating Names into Individual Columns

If you have a list of names in a column, and you want to separate those names into individual cells, there are several ...

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}] 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 eight more than 6?

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.