Written by Allen Wyatt (last updated December 1, 2018)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
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.
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!
When Excel performs a calculation, the results you see in an unformatted cell may cause a bit of concern. This tip ...
Discover MoreAddresses used in a formula can be either relative or absolute. If you need to switch between the two types of ...
Discover MoreYou can easily use the COMBIN worksheet function to determine the number of combinations that can be made from a given ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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], ... )
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments