Calculating a Sum for a Range of Dates

by Allen Wyatt
(last updated December 5, 2015)

7

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 flowing 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, and 2016.

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

Ignoring Selected Words when Sorting

If you use Excel to maintain a list of text strings (such as movie, book, or product titles), you may want the program to ...

Discover More

Duplex Printing from Multiple Trays

Printing in duplex has not always been easy in Word, particularly when you want that printing to be controlled by a macro. ...

Discover More

Entered Values are Divided by 100

Enter a value into a cell and "poof!" it is automatically divided by 100. What's going on, and how can you fix it so that ...

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)

ISO Week Numbers in Excel

Work in an industry that uses ISO standards when it comes to working with dates? You'll love the formula in this tip which ...

Discover More

Copying Dates a Year Into the Future

Need to copy a range of dates and update them to a different year? Here are a number of ways to accomplish this task with a ...

Discover More

Determining If a Year is a Leap Year

Need to figure out if a given year is a leap year? It's not as easy as you think! This tip provides a plethora of ways that ...

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 7 + 6?

2015-12-07 07:13:43

Upasana

I have a number of rows having marks for five subjects for different terms. For each student a comparative graph is to be placed. For this i place a graph in the first row and add data according to the series. Now if I copy the graph and place in second row the graph doesn't change the data accordingly. Require help for the same


2015-12-06 07:22:49

Michael (Micky) Avidan

GOOD POINT, Sanjeev.
Let us hope Allen will "pick up the glove" - the sooner the better.
A direct link to a Hosted Workbook will, dramatically, improve the tips benefit
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2016)
ISRAEL


2015-12-05 15:37:25

Sanjeev

Dear Sir,
This the First Tip i am reading after subscribing. I want to ask You a question as follows:-

don't you give examples to explain the Tips? Or we have to Buy the examples?


2015-12-05 11:20:14

allen

That might be attributed to a cultural / language difference, Michael. In the US, when someone says "in the last 90 days," they mean counting from today backwards, not the 90 days prior to the last instance.

-Allen


2015-12-05 08:11:45

Michael (Micky) Avidan

In addition and to clarify my previous post - cell [F1] holds the number of days (for any kind of calculation other than 183/365).
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2016)
ISRAEL


2015-12-05 08:04:56

Michael (Micky) Avidan

@To whom it may concern,
In the original question there was no mentioning that the recent flight, of Mr. Voss, took place TODAY.
(Mr. Forrest Voss's question was presented, to us, in the Saturday, 28/11, E-Mail)
Due to the above, to my opinion, the correct formula should read:
=SUMIF(A:A,">="&MAX(A:A)-F1+1,B:B)
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2016)
ISRAEL


2015-12-05 07:16:07

Eric Franklin

In either situation above, I would simply enter the 2 different formulas (one using 183, the other using 365) so that I always had both answers without ever changing anything. Eliminates work and the possibility of a mistake.


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.