Calculating the Average of Five Values Near the End of a Range

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


Alex has a column of values for which he needs an average of the last five values, but one. For instance, if there is data in cells A5:A36, he needs the average of the values in A31:A35, ignoring cell A36 (the "but one"). The formula needs to be dynamic, as data will be routinely added to the column.

Excel is nothing if not flexible, so there are multiple ways that this average could be computed. The first relies on the use of the OFFSET function and (obviously) the AVERAGE function:

=AVERAGE(OFFSET(A5,COUNTA(A:A)-6,0,5))

The formula works correctly, provided there are no empty rows or rows including non-numeric values. Thus, Alex should use this formula only if he has numeric values in A5 through some cell below A5. Further, it will not work correctly if the cells in A1:A4 contain other information, such as text headings.

A better solution may be to simply look at column A in its entirety, as is done in this formula:

=AVERAGE(OFFSET(A1,LOOKUP(2,1/(A:A<>""),ROW(A:A))-6,0,5,1))

This one is pretty cool, but it takes a bit of explaining. The key part of the formula is getting the row number for the last row with data. This is done using this portion of the formula:

LOOKUP(2,1/(A:A<>""),ROW(A:A))

The A:A<>"" portion creates an array that returns TRUE for non-blank cells and FALSE for blank cells. Expanding this to 1/(A:A<>"") converts the array of TRUE and FALSE values to an array with 1s (the TRUE, non-blank cells) or #DIV/0! errors (the FALSE, blank cells).

The LOOKUP function will then look for the value 2 in that array. Since there are no 2s in the range, it returns the row number from ROW(A:A) for the last occurrence of 1. In other words, it returns the row number of the row containing the last non-blank cell. Subtracting 6 from the row number yields that row where you want to start your average, and this is all plugged into the AVERAGE function to get the average of the five rows beginning at that point.

If you are using Excel 365, then I find this formula quite helpful:

=AVERAGE(TAKE(DROP(TRIMRANGE(A:A,2),-1),-5))

The TRIMRANGE function "trims" the bottom empty rows off of the range of A:A. Thus, you end up with a range from A1 through the last cell in column A that contains a value. This is fed into the DROP function, which drops a single row (-1) from the bottom of the range. This adjusted range is then fed into the TAKE function, which returns a subset of cells consisting of the last 5 cells from the bottom—the exact rows that Alex wanted. These 5 are then averaged.

As of this writing, this formula will only work properly in the version of Excel in Microsoft 365 because that's the only version that includes the TRIMRANGE function. Both DROP and TAKE are also available in Excel 2024.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13256) 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

Pointing PivotTables to Different Data

Changing the data source PivotTables go to can be a bit tricky. This tip explains what can happen when you re-point your ...

Discover More

Setting the Calculation Default

Excel can recalculate your worksheets either automatically or manually. The default is to calculate them automatically, ...

Discover More

Quickly Accessing the Column Tab

If you need to quickly display the Column tab of the Table Properties dialog box, here are some handy tricks you can use. ...

Discover More

Best-Selling VBA Tutorial for Beginners Take your Excel knowledge to the next level. With a little background in VBA programming, you can go well beyond basic spreadsheets and functions. Use macros to reduce errors, save time, and integrate with other Microsoft applications. Fully updated for the latest version of Office 365. Check out Microsoft 365 Excel VBA Programming For Dummies today!

More ExcelTips (ribbon)

Averaging Based on Multiple Criteria

When you need to determine an average based on a very small selection of cells from a large dataset, based on multiple ...

Discover More

Counting Unique Values

Need to know a count of unique values in a range of cells? There are a couple of ways you can tackle the problem.

Discover More

Determining "Highest Since" or "Lowest Since"

When compiling statistics on a collection of data points, you may want to know whether a particular value is the "highest ...

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 9 + 8?

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.