In this short tutorial, you will learn how to quickly calculate a simple moving average in Excel, what functions to use to get moving average for the last N days, weeks, months or years, and how to add a moving average trendline to an Excel chart.
In a couple of recent articles, we have taken a close look at calculating average in Excel. If you've been following our blog, you already know how to calculate a normal average and what functions to use to find weighted average. In today's tutorial, we will discuss two basic techniques to calculate moving average in Excel.
What is moving average?
Generally speaking, moving average (also referred to as rolling average, running average or moving mean) can be defined as a series of averages for different subsets of the same data set.
It is frequently used in statistics, seasonally-adjusted economic and weather forecasting to understand underlying trends. In stock trading, moving average is an indicator that shows the average value of a security over a given period of time. In business, it's a common practice to calculate a moving average of sales for the last 3 months to determine the recent trend.
For example, the moving average of three-month temperatures can be calculated by taking the average of temperatures from January to March, then the average of temperatures from February to April, then of March to May, and so on.
There exist different types of moving average such as simple (also known as arithmetic), exponential, variable, triangular, and weighted. In this tutorial, we will be looking into the most commonly used simple moving average.
Calculating simple moving average in Excel
Overall, there are two ways to get a simple moving average in Excel - by using formulas and trendline options. The following examples demonstrate both techniques.
Calculate moving average for a certain time period
A simple moving average can be calculated in no time with the AVERAGE function. Supposing you have a list of average monthly temperatures in column B, and you want to find a moving average for 3 months (as shown in the image above).
Write a usual AVERAGE formula for the first 3 values and input it in the row corresponding to the 3rd value from the top (cell C4 in this example), and then copy the formula down to other cells in the column:
=AVERAGE(B2:B4)
You can fix the column with an absolute reference (like $B2) if you want to, but be sure to use relative row references (without the $ sign) so that the formula adjusts properly for other cells.
Remembering that an average is computed by adding up values and then dividing the sum by the number of values to be averaged, you can verify the result by using the SUM formula:
=SUM(B2:B4)/3
Get moving average for a the last N days / weeks / months/ years in a column
Supposing you have a list of data, e.g. sale figures or stock quotes, and you want to know the average of the last 3 months at any point of time. For this, you need a formula that will recalculate the average as soon as you enter a value for the next month. What Excel function is capable of doing this? The good old AVERAGE in combination with OFFSET and COUNT.
Where N is the number of the last days / weeks / months/ years to include in the average.
Not sure how to use this moving average formula in your Excel worksheets? The following example will make things clearer.
Assuming that the values to average are in column B beginning in row 2, the formula would be as follows:
=AVERAGE(OFFSET(B2,COUNT(B2:B100)-3,0,3,1))
And now, let's try to understand what this Excel moving average formula is actually doing.
- The COUNT function COUNT(B2:B100) counts how many values are already entered in column B. We start counting in B2 because row 1 is the column header.
- The OFFSET function takes cell B2 (the 1st argument) as the starting point, and offsets the count (the value returned by the COUNT function) by moving 3 rows up (-3 in the 2nd argument). As the result, it returns the sum of values in a range consisting of 3 rows (3 in the 4th argument) and 1 column (1 in the last argument), which is the latest 3 months that we want.
- Finally, the returned sum is passed to the AVERAGE function to calculate the moving average.
Tip. If you are working with continuously updatable worksheets where new rows are likely to be added in the future, be sure to supply a sufficient number of rows to the COUNT function to accommodate potential new entries. It's not a problem if you include more rows than actually needed as long as you have the first cell right, the COUNT function will discard all empty rows anyway.
As you probably noticed, the table in this example contains data for only 12 months, and yet the range B2:B100 is supplied to COUNT, just to be on the save side :)
Find moving average for the last N values in a row
If you want to calculate a moving average for the last N days, months, years, etc. in the same row, you can adjust the Offset formula in this way:
Supposing B2 is the first number in the row, and you want to include the last 3 numbers in the average, the formula takes the following shape:
=AVERAGE(OFFSET(B2,0,COUNT(B2:N2)-3,1,3))
Creating an Excel moving average chart
If you have already created a chart for your data, adding a moving average trendline for that chart is a matter of seconds. For this, we are going to use Excel Trendline feature and the detailed steps follow below.
For this example, I've created a 2-D column chart (Insert tab > Charts group) for our sales data:
And now, we want to "visualize" the moving average for 3 months.
- In Excel 2013, select the chart, go to the Design tab > Chart Layouts group, and click Add Chart Element > Trendline > More Trendline Options…
In Excel 2010 and Excel 2007, go to Layout > Trendline > More Trendline Options.
Tip. If you do not need to specify the details such as the moving average interval or names, you can click Design > Add Chart Element > Trendline > Moving Average for the immediate result.
- The Format Trendline pane will open on the right-hand side of your worksheet in Excel 2013, and the corresponding dialog box will pop up in Excel 2010 and 2007.
On the Format Trendline pane, you click the Trendline Options icon, select the Moving Average option and specify the moving average interval in the Period box:
- Close the Trendline pane and you will find the moving average trendline added to your chart:
To refine your chat, you can switch to the Fill & Line or Effects tab on the Format Trendline pane and play with different options such as line type, color, width, etc.
For powerful data analysis, you may want to add a few moving average trendlines with different time intervals to see how the trend evolves. The following screenshot shows the 2-month (green) and 3-month (brick red) moving average trendlines:
Well, that's all about calculating moving average in Excel. The sample worksheet with the moving average formulas and trendline is available for download at the end of this post. I thank you for reading and look forward to seeing you next week!
Practice workbook
Calculating moving average - examples (.xlsx file)
89 comments
really good job
I am trying to use this formula to calculate the average every week for the previous 13 weeks. I used the formula above but it only calculates the average for the last 13 weeks in the range.
I want to find the maximum value of the running average (r.a.) of one list of values in a file of records. Only records should be taken into account for the r.a. which meet muliple criteria.
If this would be possible I also want to identify the location of maximum value of the r.a. in the list
Hi,
I am suwathi,I need a one help for you,How to calculate in simple moving average in shares in daily price value
I have got a set of periodic rectangular data and I want to get the equation of this data from excel? Is there any shortcut to get this equation straight out of excel?
Hi
I have a column of data which represents a length. I want to take the moving average such as L/3 <Data<2L/3 where L is the length,how can I do that please?
Data=455.8868232
452.5921169
456.2181424
453.645238
456.2600541
457.0506057
458.0431381
455.4608447
454.2369874
455.6486529
458.0613735
454.6858981
455.3989036
456.0754284
455.6650429
456.1483695
Many thanks,
V
Hello,
I am interested in creating a performance report, I will try to explain what I am looking for using only 1 row.
If cell 1A represents the first day of the month and cell 1AE represents the 31st day of the month with the total number of units sold entered into each day. Then my data in cell 1AF would equal the sum of sold units for the entire month ie. =sum(A1:AE1). My inquiry is for the following cell 1AG. I would like this cell to contain a projected total for the month running. I thought an average would work but it needs to take into consideration the remaining days left to sell. So if a person has sold 5 units on day 20 then an average based on 30 days would not be a valid projection. It would need to take the remaining 10 days as part of the equation. Not sure if this is even possible but in reading your previous comments I think if it can be done you guys would know how to do it. Thanks in advance for any help you can provide.
Thanks for neat math and good explanation.
Can we refine the formula with dividend adjusted? That reflects in price on record dates but NOT accounted in calculation.
Hi Svetlana,
First of all thanks for this helpful article. I need one info, can we show value of average point in graph. Please let me know.
Thanks,
Kiran
Hello Kiran,
The second part of this tutorial shows how to display the moving average in a graph by using the Trendline Options. If you are looking for something different, please clarify.
hello,
this gangadhar, i want to calculate 10, 20, 50 minute simple moving average with rtd data into 3 cells kindly helpme
hello,
your explanation is clear, however,
I am working on a research, I am having trouble computing VMA and FMA trading rule on Excel, that is, the simple MA is easy, but
==i am finding it difficult to differentiate between the fixed and variable moving average
==and also how to include 1% band in the calculation
=== and how to generate the buy and sell signal from the stock data
please kindly give some light on the above issues thanks
Is it possible to calculate 7 Day moving average in a pivot table?
Hi,
I have a series of data going from cell B2 onwards, where B2 is the most recent. Every month I add a new column with the latest month's value. How can I create a formula which will take the average of the last x months and which will automatically take the new value I have inserted? It seems similar to the solution provided above with taking the moving average of the last N values, but I cannot seem to tailor the formula to this situation. Please help :)
Thank you!
Hi,
Is there a way to create a spreadsheet with a formula to average 12 rolling weeks that I can also code to always put my new info in as the current week and have the data shift it's cells down by one and replace the last (or 12th) cell of data thus giving me a new rolling 12 week average?
Hi, I have a similar need. I need to create a report that will show new client visits, total client visits and other data. All of those fields are updated daily on a spreadsheet, I need to pull that data for the previous 3 months broken down by month, 3 weeks by weeks, and last 60 days. Is there a VLOOKUP, or formula, or something I could do that will link to the sheet being updated daily that will also allow my report to update daily?
Hello Everyone,
Is there a way to get a sum of a number for the last 6 months?
I want to be able to calculate the sum for the last 6 months every day. So ill need it to update every day.
I have an excel sheet with columns of every day for the last year and will eventually add more every year.
any help would be greatly appreciated as I am stumped!
Please help with the correct formula to calculate the sum of hours entered on a moving 7 day period. For example. I need to know how much overtime is worked by an individual over a rolling 7 day period calculated from the beginning of the year to the end of the year. The total amount of hrs worked must update for the 7 rolling days as I enter the overtime hours in on a daily basis
Thank you
I am looking for something very similar! I am looking for the last 6 months! I'm so stumped!
Hi, I am impressed with the vast knowledge and the concise and effective instruction you provide. I too have a query which I hope you can lend your talent with a solution as well.
I have a column A of 50 (weekly) interval dates. I have a column B next to it with planned production average by week to complete target of 700 widgets (700/50). In the next column I sum my weekly increments to date (100 for example) and recalculate my remaining qty forecast avg per remaining weeks (ex 700-100/30).
I would like to replot weekly a graph starting with the current week (not the beginning x axis date of the chart), with the summed amount (100) so that my starting point is the current week plus the remaining avg/week (20), and end the linear graph at end of week 30 and y point of 700.
The variables of identifying the correct cell date in column A and ending at goal 700 with an automatic update from today's date, is confounding me.
Could you help please with a formula? (I've been trying =IF logic with =Today and just not solving it.)
Thank you
I want to do an hourly moving average of data that has a different number of observations for each hour (2 to 6 observations).
Can you help?
any body please can help to set excl formula to get the daily moving ave of product A, B, and C for the given sample details