This is why it “works” in E5 and E6.

When the current row number is less than 3, the formula returns #N/A.

Otherwise, the formula returns a moving average as before.

Moving average chart example

The general form is:

where n is the number of periods to include in each average.

As above, OFFSET returns a range that is passed into the AVERAGE function.

Below you’re able to see this formula in action, wherenis thenamed rangeE2.

Moving average chart example

Starting at cell C5, OFFSET constructs a range that extends back to previous rows.

This is accomplished by using a height equal to negativen.

One solution is to “cap” the size of the range to the number of data points available.

Moving average chart example

A nice feature of the OFFSET option is that n can be easily changed.

The attached spreadsheet has workaround formulas for Google Sheets.

OFFSET is handy in formulas that require a dynamic range.

Moving average chart example

AVERAGE Function

The Excel AVERAGE function calculates the average (arithmetic mean) of supplied numbers.

MIN Function

The Excel MIN function returns the smallest numeric value in the data provided.

The MIN function ignores empty cells, the logical values TRUE and FALSE, and text values.

Moving average chart example

Moving average range problem

Moving average with #n/a for insufficient data

Moving average with OFFSET function

Moving average with OFFSET function and capped range

Moving average chart with OFFSET function

Excel formula: Average last n rows

Excel formula: Sum top n values

Excel formula: Sum top n values with criteria

Excel formula: Average last 3 numeric values

Excel OFFSET function

Excel AVERAGE function

Excel MIN function