Maximum Values within a Specific Hour Each Day

Written by Allen Wyatt (last updated March 14, 2026)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365


Harry has a list of sensor readings in a worksheet. Column A contains the date and time of the reading, and column B contains the actual reading. Since these are raw sensor readings, they are in ascending order based on column A. Harry would like to determine the maximum sensor reading that occurs between 8:00 pm and 9:00 pm each day.

The way you should approach this task depends, in large part, on the version of Excel you are using. If you want something that will work in any version of Excel, then start by putting together a list of dates that are represented in column A. You can put this list in column D and put it together manually, or you could assemble the date list automatically if you use the UNIQUE function. (This function is available in Excel 2021 and Microsoft 365.)

=UNIQUE(INT(A2:A10000))

With the date list constructed, we'll assume that the first date is in cell D2. In cell E2 you can place the following formula:

=MAX((IF((A:A>=(D2+TIME(20,0,0)))*(A:A<=(D2+TIME(21,0,0))),B:B)))

Copy the formula down as many cells as necessary, and you'll have the maximum reading between 8:00 pm and 9:00 pm for each date.

If you are using Excel 2019, Excel 2021, Excel 2024, or Microsoft 365, you could use the MAXIFS function. Place the following into cell E2 and copy down as many cells as necessary:

=MAXIFS(B:B,A:A,">="&D2+(20/24),A:A,"<="&D2+(21/24))

Note, as well, that this formula doesn't use the TIME function to calculate the beginning and ending times. Instead, it simply divides 20 (the hour number for 8:00 pm) and then does the same thing for the ending hour. You can use this approach or the TIME function approach; either will work fine.

If you are using Microsoft 365, you can use a formula that will spill both the dates and the maximum reading that occurred between 8:00 pm and 9:00 pm on those dates. Here is the formula broken out to multiple lines for easier understanding:

=LET(
    TD, TRIMRANGE(A2:A10000),
    RD, TRIMRANGE(B2:B10000),
    u, UNIQUE(INT(TD)),
    HSTACK(
        u,
        MAP(
            u,
            LAMBDA(
                x,
                MAXIFS(
                    RD,
                    TD, ">="&x+(20/24),
                    TD, "<"&x+(21/24)
                )
            )
        )
    )
)

TD references all the dates and RD all the readings for those dates. The u variable is used to extract a unique range of dates from the dates and times. The MAP function processes each of the unique dates individually, while the LAMBDA function uses MAXIFS to determine the maximum reading in the desired hour.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13967) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, 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

Colors and Fonts for Worksheet Tabs

Changing the color used on a worksheet tab is easy. Just follow the three steps in this tip.

Discover More

Aligning a Paragraph in a Macro

If you are applying formatting from within a macro, you may want to change the alignment of various paragraphs. Here's ...

Discover More

Counting Consecutive Negative Numbers

If you have a range of values that can be either positive or negative, you might wonder how to determine the largest ...

Discover More

Dive Deep into Macros! Make Excel do things you thought were impossible, discover techniques you won't find anywhere else, and create powerful automated reports. Bill Jelen and Tracy Syrstad help you instantly visualize information to make it actionable. You’ll find step-by-step instructions, real-world case studies, and 50 workbooks packed with examples and solutions. Check out Microsoft Excel 2019 VBA and Macros today!

More ExcelTips (ribbon)

Listing Dates at Regular Intervals

Need a way to enter dates for every other Tuesday (or some other regular interval)? Excel makes it easy, providing ...

Discover More

Calculating Business Days

There are calendar days and then there are business days. Excel provides two functions (NETWORKDAYS and NETWORKDAYS.INTL) ...

Discover More

Using a Single Digit for a Year

Excel works very well with dates and times. One thing you cannot do, however, is to create a custom format that displays ...

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 four more than 2?

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.