Average Last N Rows: Excel & Sheets Formula
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
This calculator works out the average of the last N rows in a column of numbers, for example the mean of the most recent 5 sales figures or the last 7 days of temperatures. You enter the list of numbers and the value of N, and it returns the average of the final N entries, ignoring any earlier rows. The result is given as a single number, rounded to two decimal places by default.
Formula
The average of the last N rows is the sum of those N values divided by N. In symbols:
Average = (xk-N+1 + xk-N+2 + … + xk) / N
where x1, x2, …, xk are the values in the column (k is the total number of rows), and N is the number of most recent rows you want to include. If N is greater than or equal to k, the average is simply the mean of all values. The result has the same unit as the input values (e.g., if the numbers are sales in dollars, the average is in dollars).
Worked Example
Using the default values from the calculator: numbers are 10, 12, 14, 13, 15, 16 and N = 4.
- Identify the last 4 rows: 14, 13, 15, 16.
- Sum them: 14 + 13 + 15 + 16 = 58.
- Divide by N: 58 / 4 = 14.5.
The calculator gives 14.50, matching the manual calculation.
When to Use This Calculation
This is a common need in spreadsheet work and data analysis. You might want to see the average of the most recent N entries to smooth out daily fluctuations, or to track a rolling performance metric. Typical uses include:
- Calculating the average of the last 7 days of sales to get a weekly baseline.
- Finding the mean of the last 5 test scores to see recent performance.
- Computing a moving average for a time series, where N is the window size.
- Ignoring old outliers and focusing on the most current data points.
In Excel or Google Sheets, you would use a formula like =AVERAGE(OFFSET(A1, COUNT(A:A)-N, 0, N, 1)) or =AVERAGE(TAKE(A:A, -N)) in newer versions. This calculator replicates that logic without needing to set up a spreadsheet.
How to Choose N
The right value of N depends on your goal. A smaller N (like 3 or 5) reacts quickly to recent changes but is more sensitive to random fluctuations. A larger N (like 20 or 30) gives a smoother average but lags behind trends. There is no universal rule; consider the frequency of your data and how much noise you want to filter out. For daily data, a 7-day average is a natural weekly window. For monthly data, a 12-month average might be useful to account for seasonality. If you are comparing two periods, make sure N is the same for both.
Common Mistakes and Pitfalls
- Counting rows incorrectly: The last N rows are the bottom N entries in the list. If you have headers, exclude them from the data range.
- Using N larger than the data: If N exceeds the number of rows, the average of all rows is returned. This is usually what you want, but be aware it may not be what you intended.
- Including empty cells: Most spreadsheet functions ignore empty cells by default. This calculator treats empty entries as missing and excludes them from the count, so the last N non-empty rows are used.
- Rounding too early: If you round each value before averaging, you lose precision. Keep full precision until the final step.
- Confusing with moving average: The average of the last N rows is a single number for the entire dataset. A moving average is a series of such averages, one for each position. This calculator gives the final value of that series.
Limitations of the Formula
This simple average treats every row equally, which is appropriate for many situations but not all. If your data has a trend or seasonality, the average of the last N rows will be biased toward the most recent values. For example, if sales are growing, the average of the last 4 months will be higher than the average of the previous 4 months, but it won’t predict next month’s value. For forecasting, you would need a weighted average or a regression model. Also, the average is sensitive to outliers: a single extreme value in the last N rows can skew the result significantly. If you suspect outliers, consider using the median instead.
Alternative Methods
If you need a more robust measure of recent central tendency, consider:
- Median of last N rows: Less affected by outliers.
- Weighted average: Give more weight to the most recent rows, e.g., exponential smoothing.
- Moving average (rolling): Compute averages for every window of the last N rows to see the trend over time.
- Trimmed mean: Remove the highest and lowest values in the last N rows, then average the rest.
Each has its own trade-offs; the simple average is the most straightforward and is often sufficient for a quick check.
Frequently Asked Questions
How do I exclude empty cells when averaging the last N rows?
In Excel, using AVERAGE with a range that includes blanks will ignore them by default. In this calculator, empty entries are skipped, so the last N non-empty values are used. If you want to include zeros for empty cells, you would need to fill them with 0 first.
What if N is larger than the number of rows?
The calculator will simply average all available rows. For example, if you have 10 values and N=15, the result is the average of all 10. This is the same behavior as most spreadsheet functions.
Does the order of rows matter?
Yes, the order matters because “last� refers to the bottom of the list. If your data is in chronological order, the last rows are the most recent. If the order is random, the “last N� is just the final N entries in that order.
Can I use this for text or dates?
No, the average only makes sense for numeric values. For dates, you could convert them to serial numbers and average those, then convert back. For text, you would need a different statistic like the mode.
Is this the same as a moving average?
No. A moving average is a series of averages computed for each window of N rows. This calculator gives only the average of the final window. If you want the whole series, you would need to compute it in a spreadsheet or use a dedicated moving average calculator.
How do I get the average of the last N rows in Excel?
In Excel 365, you can use =AVERAGE(TAKE(A:A, -N)) where A:A is the data column and N is a cell reference or number. In older versions, use =AVERAGE(OFFSET(A1, COUNT(A:A)-N, 0, N, 1)). Both assume no blank cells in the data range.
Related
Formula used
in list | Numbers | - | 10, 12, 14, 13, 15, 16 | 0 in n | Number of last rows | - | 4 | 1 out avg | Average of last N rows | - | mean(last(list, n)) | 2
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.