Dynamic Offset Average

Gesyca_is_joy

Board Regular
Joined
Apr 24, 2014
Messages
90
Office Version
  1. 365
Platform
  1. Windows
I have a table in which I constantly add rows. I have a column in which i want to dynamically calculate the average of the past XX months.

Right now I am using the following formula in Column C for a 5 month average.

=Average(Offset(A1,COUNT(A2:A11),0,-5)

However it's not quite what I want because what i am looking for is a formula that calcuates the average for the previous 5 rows based on each cell...so row 6 would average rows 1-5, and row 7 would average rows 2-6 and so on.


ABC
MonthNumberAverage
115
219
318
417
516
615
718
819
921
1022

<tbody>
</tbody>
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
So you can't average month 5 because there aren't 5 previous months?

Just put in with relative addresses and it will change as you require.

ABC
1MonthNumberAverage
2115
3219
4318
5417
6516
761517
871817
981916.8
1092117
11102217.8
121119
131220

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
C7=AVERAGE(B2:B6)
C8=AVERAGE(B3:B7)
C9=AVERAGE(B4:B8)
C10=AVERAGE(B5:B9)
C11=AVERAGE(B6:B10)
C12=AVERAGE(B7:B11)
C13=AVERAGE(B8:B12)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
Well, yes I would bracket the final formula with an IFERROR so that it returned a blank cell if there weren't enough months to average. but the reason I didn't do the formula you wrote below is because, for the example, i am averaging 5 months. but that is also dynamic. In my actual workbook the table shown below starts at A5 and I have a value in B3 which is currently "5" and my average formula is supposed to look at this cell to figure out how many months back to calculate. that number also changes based on what I am trying to forecast.


So you can't average month 5 because there aren't 5 previous months?

Just put in with relative addresses and it will change as you require.

ABC
1MonthNumberAverage
2115
3219
4318
5417
6516
761517
871817
981916.8
1092117
11102217.8
121119
131220

<tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
C7=AVERAGE(B2:B6)
C8=AVERAGE(B3:B7)
C9=AVERAGE(B4:B8)
C10=AVERAGE(B5:B9)
C11=AVERAGE(B6:B10)
C12=AVERAGE(B7:B11)
C13=AVERAGE(B8:B12)

<tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
So your example data was not a representation? Is this example below what you want?

It may be easier if you gave examples of actual data with your expected results.

ABC
1MonthNumberAverage
21151
33192
47185
58177.5
611168.666667
7121510.33333

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1 (2)

Worksheet Formulas
CellFormula
C2
=SUMIFS($A$2:$A$7,$A$2:$A$7,"<="&A2,$A$2:$A$7,">"&A2-5)/COUNTIFS($A$2:$A$7,"<="&A2,$A$2:$A$7,">"&A2-5)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
Apologies, I’m not sure how to put a named table into this forum.

In essence, I have a named table, that i put in the month, my actual demand figures and a third column where I want to be able to calculate a dynamic average.

The columns look exactly as above (units in thousands), and i have a cell off to one side of the named table range that will hold the number of months I am trying to average, this value will change, which is why i want the formula to reference that cell instead of a hard value.

the challenge is that all the formulas i know how to write can’t come up with the combination i’m looking for without me having to manually change the formula if my base criterion (number of rows to average) changes.

but since it’s a named table, i could write the formula to reference the column names “Month”, “Demand” “Average” are the names of the columns in the table. I could reference the column names rather than the cells (B7:B15) in the formula
 
Last edited:
Upvote 0
I'm still not sure I understand as your example never gave an expected result. Is this what you want?

ABCDEF
1MonthNumberAverageNo. of Months=5
2115
3219
4318
5417
6516
761517
871816.8
981917
1092117.8
11102219

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1 (3)

Worksheet Formulas
CellFormula
C2
=IF([@Month]<6,"",SUMIFS(Number,Month,"<="&[@Month],Month,">"&[@Month]-$F$1)/COUNTIFS(Month,"<="&[@Month],Month,">"&[@Month]-$F$1))

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Worksheet Defined Names
NameRefers To
'Sheet1 (3)'!Month='Sheet1 (3)'!$A$2:$A$11
'Sheet1 (3)'!Number='Sheet1 (3)'!$B$2:$B$11

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
What you have below is almost exactly what I am looking for. the only difference is that this part of your formula "=IF([@Month]<6," is static not dynamic, so if the value in F1 changes to, say 3 (for quarterly average) then the formula would be off? I was trying to basically write the formula and wrap it in an IFERROR so that if there are not enough rows above to average and the formula ends up in an error the IFERROR would tell the cell to stay blank.


I'm still not sure I understand as your example never gave an expected result. Is this what you want?

ABCDEF
1MonthNumberAverageNo. of Months=5
2115
3219
4318
5417
6516
761517
871816.8
981917
1092117.8
11102219

<tbody>
</tbody>
Sheet1 (3)

Worksheet Formulas
CellFormula
C2=IF([@Month]<6,"",SUMIFS(Number,Month,"<="&[@Month],Month,">"&[@Month]-$F$1)/COUNTIFS(Month,"<="&[@Month],Month,">"&[@Month]-$F$1))

<tbody>
</tbody>

<tbody>
</tbody>

Worksheet Defined Names
NameRefers To
'Sheet1 (3)'!Month='Sheet1 (3)'!$A$2:$A$11
'Sheet1 (3)'!Number='Sheet1 (3)'!$B$2:$B$11

<tbody>
</tbody>

<tbody>
</tbody>

=IF([@Month]<6,

<tbody>
</tbody>
 
Upvote 0
Ok, in trying the formula I get errors. let me start fresh and see if I can do better at articulating what I am trying to achieve.

The table below has the following information
  • column A is Time Period (usually a month,denoted as a number for simplicity now.)
  • Column B is Actuals (in currency for this example)
  • Column C is Rolling Average.
  • Columns E and F are the name and number for the criterion to average.
    • the RA Value can change, but it will always represent the number of periods i want to include in my rolling average.

GOAL: I want to write a formula that will calculate the average Actuals for the previous periods, the number of which is defined in cell F1 in the table below. the total should then appear in the column C and as the formula moves down a row, the cells it averages should also move with it, however, it should ONLY ever average the number of rows above as are defined in cell F1.

Because I am using a named table that will take my formula and apply it to the entire column, the top couple rows, or any rows added on to the end that have no Actuals in them yet will always result in an error, so i want to wrap the aforementioned formula with an IFERROR so that all errors result in a blank cell.

I am sorry that I articulated this so poorly in the beginning. I tried to clarify; this problem is making me pound my head into the desk.



ABCDEF
1PeriodActualsRolling AverageRA Value=4
20110571
30216579
40314598
50410326
6051293513019
7061475513610
8071642913154
9081058813611
10091193213677
1110959813426
12111975612137
13121235812969

<tbody>
</tbody>
 
Upvote 0
Hi,

RollingAverage: =IF(COUNT(OFFSET([@Actuals],-$F$1,,$F$1,))<>$F$1,"",AVERAGE(OFFSET([@Actuals],-$F$1,,$F$1,)))


CTRL+SHIFT+Enter

:cool:


Greetings



Christian
 
Upvote 0
Have you tried

=IF((ROW([@Demand])-ROW([[#Headers][@Demand]))<$B$3,"",AVERAGE(OFFSET([@Demand],,-$B$3))
 
Upvote 0

Forum statistics

Threads
1,214,407
Messages
6,119,332
Members
448,888
Latest member
Arle8907

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top