How to Average Last N Columns in Excel

Learn multiple Excel methods to average last n columns with step-by-step examples and practical applications.

excelformulaspreadsheettutorial
13 min read • Last updated: 7/2/2025

How to Average Last N Columns in Excel

Why This Task Matters in Excel

In every data-driven department—finance, sales, marketing, manufacturing, education, or healthcare—reports often grow from month to month or from week to week. Your worksheet might start with January in column B, February in column C, and keep expanding until a December column eventually sits out in column M. Managers rarely care about the entire history in every meeting; they want to know “How did we do over the last three months?” or “What is the rolling average of the previous six quarters?” Averaging the last N columns allows you to produce those rolling metrics instantly, without rewriting formulas every time a new column is added.

Scenarios appear everywhere:

  • A marketing analyst tracks click-through rates for weekly campaigns and wants the average of the latest eight weeks, no matter how many weeks are in the sheet.

  • A production supervisor records daily defect counts in columns stretching across the sheet. Quality reports require the average of the last five production days, even when additional days are appended daily.

  • A teacher logs test scores for each assessment, adding a new column for every quiz. The semester grade definition uses the most recent four quizzes exclusively, discarding the earliest ones automatically.

Excel shines in these situations because its grid layout naturally accommodates expanding time-series data. However, a static formula such as =AVERAGE(B2:M2) demands manual edits when a new column appears in N. Failure to adapt leads to inaccurate rolling metrics—incorrect bonuses, misguided operational decisions, or misreported KPIs. Learning to create self-adjusting formulas that always look at the last N columns guards against those risks, improves report reliability, and deepens understanding of dynamic range techniques crucial for dashboards, Power Pivot models, and Power BI integrations.

Best Excel Approach

The most robust modern solution combines two dynamic-array functions available in Microsoft 365 or Excel 2021: TAKE and AVERAGE wrapped inside LET for clarity. TAKE can slice the last N columns, and AVERAGE then calculates the mean of that slice. Using LET lets you assign friendly variable names, making long formulas easier to audit.

=LET(
   lastCols,  TAKE(dataRange,, -N),
   AVERAGE(lastCols)
)

Why this works

  • dataRange is the entire horizontally growing table (for example [B2:Z2] for one row, or a multi-row range).
  • In TAKE, omitting the row argument and supplying a negative number for the column argument tells Excel to keep all rows but return the last N columns.
  • The result is a dynamic array that expands or contracts automatically when more columns are added to dataRange.
  • AVERAGE then processes exactly those columns.

When to use it
Choose this method whenever you have access to Microsoft 365 or Excel 2021 and you need a formula that recalculates instantly without helper columns or volatile functions like OFFSET. It is transparent, fast, and compatible with the spill behavior of modern Excel.

Alternative for earlier versions (Excel 2019 and earlier)

=AVERAGE( INDEX(fullRange, , COLUMNS(fullRange)-N+1) :
          INDEX(fullRange, , COLUMNS(fullRange)) )
  • INDEX(fullRange, , columnNumber) returns a reference to an entire column within fullRange because the row number is omitted.
  • The first INDEX points to the first column in the last N, while the second points to the last column overall. The colon operator : builds a multi-column reference between them.
  • This works in any version back to Excel 2003 and avoids volatile OFFSET.

Parameters and Inputs

Before building the formula, you need:

  • dataRange / fullRange – A continuous rectangle that covers all potential columns you might ever collect. It can be a structured Table (preferred) or a normal range such as [B2:Z100]. Data types inside must be numeric if you wish to average them; text or blanks are ignored by AVERAGE.

  • N – The count of most recent columns to include. This may be a constant (like 3) or a cell reference (such as [C1]) so users can change the window width without editing the formula. N must be a positive integer less than or equal to the total number of columns in dataRange; if N exceeds the count, TAKE returns the entire range.

  • Structured Tables vs plain ranges – If dataRange is a Table named Sales, you can write Sales[[#All],[Jan]:[Dec]] for the full range, and Excel will expand automatically when a new column is added. In the INDEX approach, use Sales directly to simplify.

  • Edge cases – Blank rows within the selected slice are fine—AVERAGE ignores blank cells. However, #DIV/0! will appear if every cell inside the slice is blank or contains no numbers. For mixed data types (e.g., text headers in the same row as numbers), make sure your selection starts in the numeric row, not the header row.

Step-by-Step Examples

Example 1: Basic Scenario

Imagine a worksheet tracking monthly revenue in row 2: columns B to M hold Jan–Dec. Management wants the average revenue of the last three months.

  1. Sample data

    • Cell A2 contains the label “Revenue”.
    • B1:M1 contain month names.
    • B2:M2 contain revenue values: 12000, 13500, … 16500.
  2. Convert to an Excel Table (recommended)

    • Select B1:M2.
    • Press Ctrl + T and confirm “My table has headers”.
    • Rename the Table to RevenueTbl in Table Design → Table Name.
  3. Enter N

    • In cell P1 type “Months to Average”.
    • In P2 type 3. Format as Number with no decimals.
  4. Create the formula using TAKE

    • In cell Q2 enter:
    =LET(
       last, TAKE(RevenueTbl[@[Jan]:[Dec]],, -P2),
       AVERAGE(last)
    )
    
  5. Inspect the result
    If the final three months values are 15800, 16200, 16500, the formula returns 16166.67. Try changing P2 to 6; the formula automatically uses Jul–Dec. Append a new column “Jan 24” at the end of the Table and watch the formula roll forward automatically.

Why it works
RevenueTbl[@[Jan]:[Dec]] returns the entire row of numeric revenue. TAKE keeps only the trailing columns specified by ‑P2. Because the reference is structured, any new month column is automatically inside the Table and part of the formula’s raw data—it needs no maintenance.

Troubleshooting

  • If you forgot the negative sign before P2, TAKE gives the first N columns, not the last.
  • If Table headers contain spaces, confirm you referenced them correctly with square brackets, e.g., [@[Jan 23]:[Dec 23]].

Example 2: Real-World Application

Scenario: A regional sales director tracks daily units sold for five separate stores. Data is laid out in rows 3-7, with one row per store. Every business day a macro adds a new column to the right, labeled with the date “2024-05-31”, “2024-06-03”, etc. The weekly executive dashboard shows the average units sold during the last 7 days for each store.

  1. Data setup

    • Range B2 is the first date, and new dates extend horizontally.
    • Rows 3-7 are Store A through Store E.
    • Convert B2:ZZ7 to a Table named Units.
  2. Dynamic window control

    • Cell A1 contains “Days Window”.
    • Cell B1 (outside the Table) holds 7, allowing managers to tweak the window.
  3. Formula positioned in column A, row 3
    In A3 (Store A), enter:

    =LET(
        lastDays, TAKE(Units[@],, -$B$1),
        AVERAGE(lastDays)
    )
    
    • Drag A3 down to A7. Each row evaluates within its own [ @ ] scope, so A4 averages Store B automatically, and so on.
  4. Business impact
    The director prints the dashboard every Monday morning. Because the sheet is updated by a macro that copies entire columns from a warehouse export, the dynamic Table range plus TAKE guarantees last 7 days are always correct—no manual edits, no array resizing.

  5. Integration with Conditional Formatting
    Add a format rule to highlight any store whose 7-day average falls below its monthly target in column C. The formula =$A3<$C3 (targets) references the calculated rolling average—seamless synergy.

Performance considerations
With five stores and perhaps 260 columns (one trading day each), the TAKE+AVERAGE approach is lightning fast because it calculates only [5 × 7] elements, not the entire historical matrix. In contrast, a SUMPRODUCT solution over the entire range would process all 1,300 cells, adding unnecessary overhead.

Example 3: Advanced Technique

You have a 1,000-row financial model tracking daily closing prices of 500 stocks—half a million data points per worksheet. You need the 20-day moving average for each stock, refreshed daily, but workbook size and calculation time are critical.

  1. Avoid volatile OFFSET
    OFFSET recalculates on every workbook change, slowing large files. Use INDEX for non-volatile references.

  2. Formula in D2 for the first ticker
    The data range for each row starts in column E and expands indefinitely. In D2 (helper column dedicated to the moving average):

    =AVERAGE( INDEX(E2:ZZ2, COLUMNS(E2:ZZ2)-$B$1+1) :
              INDEX(E2:ZZ2, COLUMNS(E2:ZZ2)) )
    
    • $B$1 holds 20, the window size.
    • E2:ZZ2 is the full horizontal horizon—limits set past any realistic columns.
  3. Copy down through D1001
    Each row works independently. Calculation complexity is twice per row (two INDEX calls), not proportional to the number of columns.

  4. Memory footprint
    Unlike TAKE, INDEX does not spill arrays for older Excel; it returns references only. Therefore, the workbook remains small. File size and recalc time scale linearly with rows, not columns.

  5. Error handling
    Because some tickers may have fewer than 20 days on the sheet (new IPOs), wrap the formula:

    =IF(COLUMNS(E2:ZZ2) < $B$1,
         NA(),
         AVERAGE( INDEX(E2:ZZ2, COLUMNS(E2:ZZ2)-$B$1+1):
                  INDEX(E2:ZZ2, COLUMNS(E2:ZZ2)) ))
    

    This returns #N/A, signaling insufficient history, which charting tools can gracefully skip.

Tips and Best Practices

  1. Use Structured Tables – Tables auto-extend, so your formula’s source range grows automatically. Combine with TAKE for future-proof dashboards.
  2. Store N in a Named Cell – Rather than hard-coding, use a clearly labeled driver cell or define a Name like RollingColumns. Stakeholders can adjust without opening the formula bar.
  3. Leverage LET for Readability – Assign interim variables (lastCols) to keep formulas understandable, aiding audits and peer reviews.
  4. Avoid Volatile Functions – OFFSET, INDIRECT, and TODAY recalculate constantly. Prefer INDEX-based references or TAKE, which are non-volatile.
  5. Wrap with IFERROR for Reports – In external dashboards, return blank ("") instead of #DIV/0! when history length is less than N: =IFERROR(YourFormula,"").
  6. Document Assumptions – Add a comment near the driver cell explaining the rolling window logic, ensuring future editors understand the setup.

Common Mistakes to Avoid

  1. Positive Number in TAKE – Remember to supply a negative column count; positive keeps the first N columns. Verify by temporarily wrapping with =TEXTJOIN(",",,TAKE(...)) to inspect output.
  2. Range Misalignment – Selecting rows with headers inside your numeric range leads to #VALUE! errors. Ensure dataRange excludes header rows.
  3. Hard-Coding the Colon Reference Wrong – In the INDEX approach, mixing relative and absolute references can shift as you copy down. Anchor column counts ($B$1), but leave row numbers relative.
  4. Overlooking Blank Columns – A blank column inside the last N reduces the average unexpectedly. Consider replacing blank cells with 0 only if your business rule treats missing values as zero; otherwise, leave blanks so AVERAGE skips them.
  5. Neglecting Calculation Mode – In Manual calculation mode, new columns may appear without recalculation. Press F9 or switch back to Automatic to avoid stale values.

Alternative Methods

Different needs or Excel versions might favor other approaches:

MethodExcel VersionVolatile?ComplexityProsCons
TAKE + AVERAGE365/2021NoLowSimple, spill aware, auto-expandsRequires latest Excel
INDEX + Colon2003+NoMediumWorks everywhere, non-volatileMore arguments, less intuitive
OFFSET + AVERAGE2003+YesLowEasy to write, supports dynamic sizeSlower on large sheets, volatile
SUM and COUNTA2003+NoMediumAllows weighted averages, custom denominatorsTwo formulas required
Power Query2010+ w/ add-inNoHighPre-aggregates before load, efficient for big dataNot real-time, requires refresh

Use OFFSET only for quick prototypes or very small workbooks where volatility cost is negligible. In enterprise models, choose INDEX or TAKE for stability. For massive datasets, push the calculation to Power Query or Power Pivot to offload memory and CPU.

FAQ

When should I use this approach?

Use a last-N-columns formula whenever your data grows horizontally over time, your metric is a rolling average, and you need results to update automatically each time a new column is added. Typical examples are moving averages, rolling defect rates, and trailing revenue per quarter.

Can this work across multiple sheets?

Yes. Wrap the sheet reference around the range. For example

=LET(last, TAKE('StoreData'!B2:Z2,, -$C$1), AVERAGE(last))

In the INDEX method, prefix both INDEX arguments with the sheet name in single quotes.

What are the limitations?

  • TAKE requires Microsoft 365 or Excel 2021.
  • If all cells in the last N columns are blank, AVERAGE returns #DIV/0!.
  • Dynamic arrays cannot spill leftward, so place the formula in a column that will not be obstructed by spill output (if you display the slice itself).
  • Structured Tables cannot exceed 16,384 columns; index methods rely on that hard limit.

How do I handle errors?

Wrap with IFERROR or IF to test the number of columns available. For example:

=IF(COLUMNS(dataRange) < N, "Not enough data", LET(...))

This prevents #DIV/0! from propagating into linked dashboards.

Does this work in older Excel versions?

The INDEX technique works in every version since Excel 2003. OLD Excel will not understand TAKE or LET, so use the traditional syntax. Structured Tables appeared in Excel 2007, but INDEX works on normal ranges in 2003.

What about performance with large datasets?

INDEX is efficient because it returns a direct reference without scanning the entire range. TAKE is similarly efficient and leverages the new calculation engine. OFFSET can slow down workbooks larger than roughly 10,000 cells because of volatility. For hundreds of thousands of cells, consider moving the calculation into Power Query or a cube measure.

Conclusion

Mastering a self-adjusting average of the last N columns liberates you from endless manual edits and guards against silent calculation errors as your worksheets expand. Whether you use modern dynamic functions like TAKE or the time-tested INDEX method, the underlying concept—building a reference that moves with your newest data—is foundational for rolling metrics, dashboards, and financial models. Apply these techniques, practice with real datasets, and explore pairing them with other dynamic tools such as XLOOKUP, FILTER, and charting to elevate your Excel proficiency even further.

We use tracking cookies to understand how you use the product and help us improve it. Please accept cookies to help us improve.