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

Weird Characters in File Names

If you ever end up with file names that contain percent signs followed by numbers, it could be due to some sort of file ...

Discover More

Appending to a Non-Excel Text File

Does your macro need to add information to the end of a text file? This is called appending, and is done using the ...

Discover More

Transposing Two Paragraphs

Need to swap two adjacent paragraphs? Your editing arsenal can include a command to do this if you use the macro in this tip.

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Tombstone Date Math

Doing math with dates is easy in Excel. Doing math with old dates, such as those you routinely encounter in genealogy, is ...

Discover More

Converting Time Notation to Decimal Notation

Want to convert an elapsed time, such as 8:37, to a decimal time, such as 8.62? If you know how Excel stores times ...

Discover More

Including Weeks in Elapsed Time

When showing how much time has elapsed between two dates, it is sometimes helpful to express the result in terms of ...

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 less than 4?

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.