Calculating a Sum for a Range of Dates

Written by Allen Wyatt (last updated October 31, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


Forrest has an Excel worksheet in which he logs flight hours. There are two primary columns: Column A is the date of the flight and column B is the number of hours flown for that particular flight. There can be multiple flights per day, so multiple rows per day. Forrest is continually adding rows to the flight log and he needs a way to calculate the number of hours flown over the last X days, where X could be 183 (6 months) or 365 (12 months).

There are all sorts of ways you could approach this problem, but there are actually a couple of simple formulas you could use to get the desired results. If, for instance, you wanted to determine the number of hours flown in the past 183 days, you could use the following formula:

=SUMIF(A:A,">="&(TODAY()-183),B:B)

You can, of course, change the 183 in the formula to 365 to get the hours for the past year. Or, you could simply change 183 to a cell reference (such as E1) and then put the desired number of days into that cell. The SUMIF function includes in its "summing" only those values that match some criteria that you specify. In this case, the criteria is that the dates in column A must be greater than or equal to 183 days before today.

You could also use the SUMIFS function to create a formula that may be equally as useful. The SUMIFS function allows you to test multiple criteria in determining what is summed. Assume, for a moment, that you had a starting date in cell G1 and an ending date in cell G2. You could then use the following formula to determine the number of hours flown between those two dates:

=SUMIFS(B:B,A:A,">="&G1,A:A,"<="&G2)

The formula only sums values in column B if the dates in column A are greater than or equal to your starting date (cell G1) and less than or equal to your ending date (cell G2).

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10049) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.

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 SUM In a Macro

Want to use a worksheet function (such as SUM) from within a macro? Here's how easy it is to accomplish the task.

Discover More

Using Copy and Paste for Formatting

Want to copy formatting from one cell and paste it into another cell? It's easy to do if you use the Paste Special ...

Discover More

Importing CUSIP Numbers Correctly

It is often necessary to import information from other programs into Excel. Sometimes this can lead to challenges, such ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Pushing Dates Into Last Month

Excel is great when it comes to working with dates and times. You can even do math on dates. One such easy manipulation ...

Discover More

Calculating the First Business Day of the Month

Want to know which day of the month is the first business day? The easiest way to determine the date is to use the ...

Discover More

Calculating a Group Retirement Date

Calculating a retirement date can be as simple as doing some date math to see when a person reaches a certain age. ...

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 8 - 5?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


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.