Menu

OFFSET in Excel: Dynamic Ranges and Rolling Totals

=OFFSET(A1,3,2) returns the cell 3 rows down and 2 columns across from A1. With a height it returns a whole range, which is how you total the last N rows or build a rolling average.

Every sheet on this page is live: change a number or a formula and it recalculates.

=OFFSET(A1,3,2) returns the cell 3 rows down and 2 columns across from A1, which is C4. Give it a height and width as well and it returns a whole range, which is what OFFSET is mostly used for: totals and averages over a range that moves or grows.

Move from A1
G2
ABCDEFG
1ProductCategoryPriceRowsColsResult
2AppleFruit$1.2032$0.80
3PearFruit$1.50
4CarrotVegetable$0.80
5BreadBakery$2.40
6MilkDairy$1.10
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

3 rows down and 2 across from A1 lands on C4, Carrot's price, $0.80. Set Cols to 0 for the name Carrot, or Rows to 5 for Milk's row. Rows and columns can be negative to move up or back, and a move off the top or edge of the sheet is #REF!.

OFFSET syntax

=OFFSET(reference, rows, cols, [height], [width])
  • reference: the start cell (or range).
  • rows, cols: how far to move. 0 means stay.
  • height, width: the size of the range to return, counted from the moved-to cell. Left out, they are the size of reference.

On its own in a cell, an OFFSET that returns several cells spills in Excel 365; older versions usually show #VALUE!. Inside SUM, AVERAGE, COUNT or MAX it works as a range.

Sum the last N rows

The classic OFFSET job: a total that always covers the most recent rows, however many have been added. COUNT finds how many values there are, OFFSET moves down to the first of the last N, and the height takes N rows.

Total of the last N months
F2
ABCDEF
1MonthSalesLast NTotal
2Jan4,200314,900
3Feb3,900
4Mar4,800
5Apr5,100
6May4,600
7Jun5,300
8Jul5,000
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

There are 7 values, so OFFSET starts 7-3+1, 5 rows below B1, at B6, and takes 3 rows: May to Jul, 14,900. Type 4900 into B9 (August) and the total moves to Jun, Jul and Aug, because COUNT now finds 8. The range B2:B13 leaves room for the rest of the year. The column must have no empty cells in between, or COUNT undercounts and the window lands in the wrong place.

A rolling average

Filled down a column, OFFSET with a negative row offset gives each row a window of the rows above it: here the average of the current month and the two before it.

Three-month rolling average
C4
ABC
1MonthSales3-month average
2Jan4,200
3Feb3,900
4Mar4,8004,300
5Apr5,1004,600
6May4,6004,833
7Jun5,3005,000
8Jul5,0004,967
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

C4 averages B2:B4 (Jan to Mar), 4,300. Each row below moves the window down by one. Change the 3 to 6 and the -2 to -5 for a six-month average (start the formula in row 7 then). This particular case needs no OFFSET at all: =AVERAGE(B2:B4) filled down from C4 does the same, because relative references already move. OFFSET earns its place when the window size comes from a cell.

Why INDEX is often the better choice

OFFSET is volatile: Excel recalculates every OFFSET after any edit anywhere in the workbook, since it cannot know in advance which cells it will point to. A sheet with thousands of them gets slow. INDEX returns a reference too, and a range written as start:INDEX(...) grows the same way without being volatile:

=SUM(OFFSET(B2, 0, 0, E2, 1))        first E2 rows, volatile
=SUM(B2:INDEX(B2:B13, E2))           same rows, not volatile

Both read the first E2 rows of the column. OFFSET is also harder to audit: Trace Precedents and the coloured outlines Excel draws while you edit the formula show the start cell and the arguments, not the range OFFSET ends up returning. Use OFFSET for a quick model or a chart range; prefer INDEX in big workbooks. INDEX has more on returning ranges, and INDIRECT is the other volatile reference function.

Practice: total of the first N months

Monthly sales
F2
ABCDEF
1MonthSalesFirst NTotal
2Jan4,2004
3Feb3,900
4Mar4,800
5Apr5,100
6May4,600
7Jun5,300
8Jul5,000
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: In F2, use OFFSET inside SUM to total the first N months, where N is in E2.

Frequently Asked Questions

What does OFFSET do in Excel?

It returns a reference that is a given number of rows and columns away from a starting cell, optionally resized. =OFFSET(A1,3,2) is the cell 3 rows down and 2 columns right of A1, which is C4.

How do I sum the last N rows in Excel?

Start from the header and move down to the first of the last N values: =SUM(OFFSET(B1,COUNT(B2:B100)-N+1,0,N,1)). COUNT finds how many values there are, and the height N takes that many rows. It only works when the column has no gaps.

Why is OFFSET volatile?

Excel recalculates every OFFSET after any change in the workbook, because the cells it points to are only known after it runs. On large workbooks that slows things down. A range built with INDEX, such as B2:INDEX(B2:B100,N), does the same job without being volatile.

What are the arguments of OFFSET?

OFFSET(reference, rows, cols, [height], [width]): the start cell, how many rows down (negative is up), how many columns across (negative goes back), and optionally the size of the range to return.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED