 Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Referencing the Last Six Items in a Formula.

# Referencing the Last Six Items in a Formula by Allen Wyatt
(last updated February 12, 2020)

Darryl needs to find the average of the last six entries in a column. The number of items in the column can vary over time as more information is added, but he always wants the average of those last six items.

There are a number of different formulas you can use, probably too many to go over here in detail. With that in mind, it is instructive to look at two particular formulas. The one you choose to use will depend on the characteristics of the data in the column. If there are no blank cells in the column, then finding the average can be done with a relatively simple formula:

```=AVERAGE(OFFSET(A1,COUNT(A:A)-6,0,6,1))
```

This formula uses the OFFSET function to calculate the proper cells to examine, at the bottom of the column. As already mentioned, this formula won't work if there are blank cells in the column. In that case you will need to use a formula that examines the contents of each cell and determines, as part of the calculation process, whether it is blank or not. Array formulas or regular formulas using array functions are great for this purpose. The following example uses the SUMPRODUCT function to accomplish the task:

```=SUMPRODUCT((A1:A30*((MAX(ROW(A1:A30)*(A1:A30<>""))-ROW(A1:A30))<6))/6)
```

This formula assumes that the cells to be evaluated are in the range of A1:A30; it doesn't matter if there are blank cells in this range. The ROW functions are used to create arrays that determine if the individual cells contain values or not. Only those rows containing values end up being counted, and those are divided by 6 and summed, providing the desired average.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10770) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Referencing the Last Six Items in a Formula.

##### 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

Resetting Default Names for New Worksheets

When you add a new worksheet to a workbook, Excel gives it a default name that consists of "Sheet" followed by a number. ...

Discover More

Displaying a Calendar

Want to know what today is? How about the date for next Thursday or the second Friday in October? Windows can display a ...

Discover More

Determining Font Formatting

If you need to determine the font applied to a particular cell, you’ll need to use a macro. This tip presents several ...

Discover More Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

##### More ExcelTips (ribbon)

Summing Digits in a Value

Want to add up all the digits in a given value? It's a bit trickier than it may at first seem.

Discover More

Deriving a Secant and Cosecant

Two rather common trigonometric functions are secants and cosecants. Excel doesn't provide functions to calculate these, ...

Discover More

Counting Names Based on Two Criteria

Need to figure out how many rows in a worksheet meet two criteria that you specify? Here's how to get the info you desire.

Discover More
##### Subscribe

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

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

2016-05-09 16:29:17

Barbara Toosley

THANK YOU. Been trying for 2 years to be able to write a formula calculate our golf handicaps and you have now answered by prays.

2016-04-01 17:48:27

Dennis Costello

To be clear, the SUMPRODUCT formula returns the average of 6 rows, the last of which is the last populated row in the range A1:A30. For example, if there are values in rows 1,2,3,6,7,10,12,13,14 - it will give the average of the cells A9:A14, even though two of those cells are empty.

This array formula (that uses some ideas from yours) returns the proper result:

{=AVERAGE(OFFSET(A1, LARGE(ROW(A1:A30) * (A1:A30 <> ""), 6) - 1, 0, 30, 1))}

2015-09-27 15:39:40

Paul

=SUMPRODUCT((A1:A30*(ROW(A1:A30)>=LARGE((ROW(A1:A30)*(A1:A30<>"")),6)))/6)

The Large expression finds the 6th highest non-blank row.

The >= test returns 1 only for rows greater than or equal to the 6th highest non-blank row, so only these values are averaged.

I'm guessing a macro would give a simpler solution.

2015-06-29 12:31:19

Kirk

None of these give the correct result if there is a blank cell within the 6 desired for averaging. Consider alternating values of 2 or 3 with a blank at row 27 (1=2, 2=3,...26=3, 27=blank, 28=2). The average of non-blank cells among the last 6 is 2.4 while the average of the last 6 non-blank cells is 2.5. SUMPRODUCT counts the blank as ZERO and gives an average of 2.0. AVERAGE(INDEX and AVERAGE(OFFSET average rows 24-29 and give 2.6 as the result.

2015-06-29 09:22:09

Rick

Never liked offset much due to the volitile part. Nor do I like the sumproduct array because most folks get confused reading it, so I use something simpler:

=AVERAGE(INDEX(A1:A51,COUNT(A1:A51)-5):INDEX(A1:A51,COUNT(A1:A51)))

##### 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.