Calculate Moving Average for Dynamic Range in Excel (3 Examples)

The Moving Average is also known as the Rolling Average or Running Average in Excel. In this article, we will show you how to calculate the moving average for a dynamic range in Excel with examples.


Download Workbook

You can download the free practice Excel workbook from here.


What is Moving Average?

The Moving Average means the time period of the average is the same, but it keeps moving when new data is added.

For Instance, if anyone asks you to provide the moving average of sales value on day 3, you have to give the sales value of Day 1, 2 and 3. And if anyone asks you to provide the moving average of sales value on day 4, you have to give the sales value of days 2, 3 and 4. As new data is added, you must keep the time/ interval period (3 days) the same but use the newly added data to calculate the moving average.

A moving average smooths out any irregularities (peaks and valleys) from data to easily recognize trends. The larger the interval period is to calculate the moving average, the more fluctuations smoothing occurs, as more data points are included in each calculated average.

A very efficient way to calculate a moving average is with the OFFSET function in Excel. The OFFSET function can build a dynamic range which means the range will automatically update when data is modified.

The general form of the AVERAGE function and the OFFSET function together is:

=AVERAGE(OFFSET(A1, 0, 0, -n, 1))

Here,

  • A1 = reference
  • n = the number of spans to include in each average

The above OFFSET returns a range that is passed into the AVERAGE function to extract the Moving Average of data.


3 Examples on How to Calculate Moving Average for Dynamic Range in Excel

In this phase, you will learn how to calculate the moving average for dynamic range with Excel’s OFFSET function along with the MATCH function and the COUNT function.

1. Calculate Moving Average for Specific Data in a Dynamic Range in Excel

Suppose you have a dataset of Date and Sales for each date given. You want to find the moving average for each date in a way that when you put the date in a search box and input the interval period, the moving average will be calculated. And every time you update the search value and/or interval period, the moving average will be automatically updated.

The steps on how you can do that are given below.

Steps:

  • In a cell (e.g. Cell F7), write the following formula:
=AVERAGE(OFFSET(C4,MATCH(F5,B5:B15,0)+1,0,F6,1))

Here,

  • C4 = Starting point, Column header.
  • F5 = Search value that we want to extract the moving average for (in our case, we put 12/6/2002 in that cell as an example).
  • B5:B15 = Search range where we will search the match for our search value.
  • F6 = The interval period that we want (for now, let’s have an interval of 3 for the sake of the example).
  • Press Enter. You will get the moving average of the search value for the given interval.

Calculate Moving Average for Specific Data in a Dynamic Range in Excel

Notice in the above picture, Cell F7 is carrying the result of the average of 3 (Interval) Sales values after the Date 12/6/2002 (Search Value).

Now, look at the following gif. Every time you change the intervals, the result Cell F7 will be automatically updated according to the input value. For instance, if you pass 2 as an interval period then the result of the average of 2 (Interval) Sales values after the Date 12/6/2002 (Search Value) will be displayed, if you pass 4 as an interval period then the result of the average of 4 (Interval) Sales values after the Date 12/6/2002 (Search Value) will be displayed.

Automatically update Auto update Moving Average for Specific Data in a Dynamic Range in Excel

You can also change the Search Value to extract the data for any specific date that you want. The result Cell F7 will show you the correct moving average according to the date and the interval period that you will provide.

To understand more see the gif below.

Automatically update Auto update Moving Average for Specific Data in a Dynamic Range in Excel

Formula Breakdown

  • MATCH(F5,B5:B15,0)
    • Result: 5
    • Description: The MATCH function returns the position of the search/ lookup value in the search range/ array. The syntax for the MATCH function is:

                  =MATCH(lookup_value, array, [match_type])

Here,

      • F5 = lookup_value
      • B5:B15 = array
      • 0 = [match_type], exact match

It counts the position of the search value 12/6/2002 in the range B5:B15 and finds position 5.

  • OFFSET(C4,MATCH(F5,B5:B15,0)+1,0,F6,1) -> becomes:
    • OFFSET(C4,5+1,0,F6,1)
    • Result: 220, 450, 1000
    • Description: The OFFSET function takes the cell reference C4 (1st argument) as the starting point.
      • We don’t want to include the selected date so we added a +1 to our MATCH It instructs the formula to find the selected date and go down one extra cell.
      • As we want to stay in the same column so it was set to 0.
      • Height, F6 depends on the condition. If we want to include the selected date then we must include the cell reference in the calculation.
      • The width is set to 1.
  • AVERAGE(OFFSET(C4,MATCH(F5,B5:B15,0)+1,0,F6,1)) -> becomes:
    • AVERAGE(220, 450, 1000)
    • Result: 556.6666667
    • Description: The average result of 220, 450, 1000
\

Read More: How to Calculate Average in Excel (Including All Criteria)


2. Get Rolling Average for the Last N-th Values in a Dynamic Column in Excel

Suppose you want to know the average of sales of last N amount of products of your column.

To do this, you need the formula to calculate the moving average. And the Average function can do this along with the OFFSET and the COUNT functions.

The generic formula for this is,

=Average(OFFSET(first_cell, COUNT(entire_range)-N, 0, N, 1)

Here,

  • N = the number of the values to include to calculate the average

So if we calculate the moving average for our dataset then the formula will be,

=AVERAGE(OFFSET(C5,COUNT(C5:C100)-F5,0,F5,1))

Here,

  • C5 = Start point of the range
  • F5 = The interval period that we want (for now, let’s have an interval of 3 for the sake of the example).

It will give you the moving average of the last 3 values in a dynamic column.

Moving Average for the Last N-th Values in a Dynamic Column in Excel

Notice in the above picture, Cell F6 is carrying the moving average, 700, of the last 3 (Interval) Sales values (Cell C13, C14 and C15) of Column C of our dataset.

Now, look at the following gif. Every time you change the intervals, the result Cell F6 will be automatically updated according to the input value. For instance, if you pass 2 as an interval period then the result of the average of the last 2 (Interval) Sales values of the column will be displayed, if you pass 4 as an interval period then the result of the average of the last 4 (Interval) Sales values of the column will be displayed.

Auto update of Moving Average for the Last N-th Values in a Dynamic Column in Excel

Formula Breakdown

  • COUNT(C5:C100)
    • Result: 11
    • Description: The COUNT function counts how many values are there in Column C. We started from Cell C5 because that is the starting point of the range to calculate.
  • OFFSET(C5,COUNT(C5:C100)-F5,0,F5,1) -> becomes:
    • OFFSET(C5,11-3,0,3,1)
    • Result: 1050, 300, 750
    • Description: The OFFSET function takes the cell reference C5 (1st argument) as the starting point, and balance the value returned by the COUNT function by moving 3 rows up (-3 in the 2nd argument). 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 last 3 values that we want to calculate.
  • AVERAGE(OFFSET(C5,COUNT(C5:C100)-F5,0,F5,1)) -> becomes:
    • AVERAGE(1050, 300, 750)
    • Result: 700
    • Description: Finally, the AVERAGE function calculates the returned sum values to extract the moving average.

Read More: Moving Average Formula in Excel (8 Uses with Examples)


Similar Readings


3. Extract Moving Average for the Last N-th Values in a Dynamic Row in Excel

You can also get the average of sales of the last N amount of products of your row in Excel.

The formula is almost the same as the formula with the column. Only this time, instead of including the entire range, you have to insert a fixed range.

=AVERAGE(OFFSET(C5,0,COUNT(C5:M5)-E7,0,E7,1))

Here,

  • C5 = Start point of the range
  • M5 = Endpoint of the range
  • E7 = The interval period that we want (for now, let’s have an interval of 3 for the sake of the example).

It will give you the moving average of the last 3 values in a dynamic row.

Moving Average for the Last N-th Values in a Dynamic Row in Excel

Notice in the above picture, Cell E8 is carrying the result of the average of the last 3 (Interval) Sales values (K5, L5, M5) of the row.

Now, look at the following gif. Every time you change the intervals, the result Cell E8 will be automatically updated according to the input value. For instance, if you pass 2 as an interval period then the result of the average of the last 2 (Interval) Sales values of the row will be displayed, if you pass 4 as an interval period then the result of the average of the last 4 (Interval) Sales values of the row will be displayed.

Read More: How to Calculate Average of Multiple Ranges in Excel (3 Methods)


Conclusion

This article explained how to calculate the moving average for dynamic range in Excel with 3 examples. I hope this article has been very beneficial to you. Feel free to ask if you have any questions regarding the topic.


Related Articles

Sanjida Ahmed

Sanjida Ahmed

Hello World! This is Sanjida, an Engineer who is passionate about researching real-world problems and inventing solutions that haven’t been discovered yet. Here, I try to deliver the results with explanations of Excel-related problems, where most of my interpretations will be provided to you in the form of Visual Basic for Applications (VBA) programming language. Being a programmer and a constant solution seeker, made me interested in assisting the world with top-notch innovations and evaluations of data analysis.

We will be happy to hear your thoughts

Leave a reply

ExcelDemy
Logo