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

**Excel Smarts for Beginners!** Featuring the friendly and trusted *For Dummies* style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out *Excel 2013 For Dummies* today!

Want to find out how many of a particular weekday occurs within a given month? Here's how you can find the desired ...

Discover MoreNeed to calculate the date that is a certain number of workdays in the future? You can do so using a couple of different ...

Discover MoreExcel is brilliant at handling datesâ€"as long as they aren't dates earlier than the base date used by the program. If ...

Discover More**FREE SERVICE:** Get tips like this every week in *ExcelTips,* a free productivity newsletter. Enter your address and click "Subscribe."

2020-01-07 17:41:38

J. Woolley

Here is another formula that gives the same result, but this must be entered as an array formula (Ctrl+Shift+Enter):

{=SUM(IF(MONTH(A$2:A2)=MONTH(A2),B$2:B2))}

2020-01-07 14:16:46

J. Woolley

Assuming the table starts with a heading in row 1, date in column A, hours in column B, and hours/month in column C, enter either of these formulas in cell C2, then duplicate it down column C:

=IF(ISERROR(MONTH(A1)),B2,IF(MONTH(A2)<>MONTH(A1),B2,C1+B2))

=SUMPRODUCT((MONTH(A$2:A2)=MONTH(A2))*1,B$2:B2)

Either formula gives the same result.

2020-01-06 09:43:28

Amjad Alsharif

2020-01-06 09:41:54

Amjad Alsharif

What formula would I use to add totals hours per month?

2019-11-29 23:18:15

Kelli

2015-12-07 07:13:43

Upasana

2015-12-06 07:22:49

Michael (Micky) Avidan

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

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

-Allen

2015-12-05 08:11:45

Michael (Micky) Avidan

--------------------------

Michael (Micky) Avidan

â€śMicrosoftÂ® Answers" - Wiki author & Forums Moderator

â€śMicrosoftÂ®â€ť MVP â€“ Excel (2009-2016)

ISRAEL

2015-12-05 08:04:56

Michael (Micky) Avidan

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

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 © 2020 Sharon Parq Associates, Inc.

## Comments