Hi, LStreet!
I assumed your formulas for previous years were correct... once, time ago, and that you've never updated them since then. So I went on and arrived to this new monster. Give a look at this file:
https://dl.dropboxusercontent.com/u/60558749/Moving Averages_ Auto Calculating Similar Weeks Between Multiple Years - Moving Averages (for LStreet at chandoo.org).xlsx
It uses a few (6) dynamic -most except MinCell- ranges:
MinCell: cell of column A where totals start
=Sheet1!$A$709
DateTable: columns A: D, yes, 2 columns added
=DESREF(Sheet1!$A$4;;;CONTARA(INDIRECTO("Sheet1!$A$4:$A$"&COINCIDIR(MinCell;Sheet1!$A:$A)-1));CONTARA(Sheet1!$4:$4)) -----> in english: =OFFSET(Sheet1!$A$4,,,COUNTA(INDIRECT("Sheet1!$A$4:$A$"&MATCH(MinCell,Sheet1!$A:$A)-1)),COUNTA(Sheet1!$4:$4))
DateList: column A
=DESREF(DataTable;;0;;1) -----> in english: =OFFSET(DataTable,,0,,1)
InventoryList: column B
=DESREF(DataTable;;1;;1) -----> in english: =OFFSET(DataTable,,1,,1)
YearList: column C
=DESREF(DataTable;;2;;1) -----> in english: =OFFSET(DataTable,,2,,1)
WeeknumList: column D
=DESREF(DataTable;;4;;1) -----> in english: =OFFSET(DataTable,,4,,1)
I found that most of the dates are Fridays, and the list of that who aren't is at work range L708:L717. This might lead to differences as with the criteria used for the WEEKNUM function to start counting weeks per year. I added 2 work columns E:F to show the differences.
Formulas:
C4: =AÑO(A4) -----> in english: =YEAR(A4)
D4: =NUM.DE.SEMANA(A4;16) -----> in english: =WEEKNUM(A3,16) (16 as starting week on Saturday as your dates are on Fridays, assumed end of the week; if start, then it should be changed to 15)
E4: =CONTAR.SI(C$4:C4;C4) -----> in english: =COUNTIF(C$4:C4,C4)
F4: =SI(D4<>E4;"X";"") -----> in english: =IF(D4<>E4,"X","")
Totals.
If you agree to keep the current layout (i.e., 3 row for min/max/avg, 2 blank rows, and then a group of 4 rows (3 + 1 blank) for each year you'd be able to use only 2 formulas: one for column A and another one for column B, as described below.
Changed the minimum, maximum and average formulas to:
=MIN(InventoryList)
=MIN(InventoryList)
=PROMEDIO(InventoryList) -----> in english: =AVERAGE(InventoryList)
Copied previous totals and formulas to work range I708:J729 for witness purposes.
Added 3 formulas at work range C708:E729 to illustrate about how to calculate (relative to MinCell range):
row diff: C709: =FILA()-FILA(MinCell) -----> in english: =ROW()-ROW(MinCell)
mod 4: D709: =RESIDUO(FILA()-FILA(MinCell);4) -----> in english: =MOD(ROW()-ROW(MinCell),4)
int / 4: E709: =ENTERO((FILA()-FILA(MinCell)-1)/4)-1 -----> in english: =INT((ROW()-ROW(MinCell)-1)/4)-1
used to embed in the next formulas.
Year block: 3 + 1 blank row
Column A: YYYY N WK MA (format)
=(SI(FILA()-FILA(MinCell)>4*2;AÑO(MAX(DateList))-(ENTERO((FILA()-FILA(MinCell)-1)/4)-1);"Current")&" "&RESIDUO(FILA()-FILA(MinCell);4)*4&" WK MA") -----> in english: =(IF(ROW()-ROW(MinCell)>4*2,YEAR(MAX(DateList))-(INT((ROW()-ROW(MinCell)-1)/4)-1),"Current")&" "&MOD(ROW()-ROW(MinCell),4)*4&" WK MA")
Column B: moving average
=SUMAPRODUCTO((YearList=AÑO(MAX(DateList))-(ENTERO((FILA()-FILA(MinCell)-1)/4)-1))*(WeeknumList>=DESREF(WeeknumList;FILAS(WeeknumList)-1;1;1)-(RESIDUO(FILA()-FILA(MinCell);4)*4)+1)*(WeeknumList<=DESREF(WeeknumList;FILAS(WeeknumList)-1;1;1))*(InventoryList))/(RESIDUO(FILA()-FILA(MinCell);4)*4) -----> in english: =SUMPRODUCT((YearList=YEAR(MAX(DateList))-(INT((ROW()-ROW(MinCell)-1)/4)-1))*(WeeknumList>=OFFSET(WeeknumList,ROWS(WeeknumList)-1,1,1)-(MOD(ROW()-ROW(MinCell),4)*4)+1)*(WeeknumList<=OFFSET(WeeknumList,ROWS(WeeknumList)-1,1,1))*(InventoryList))/(MOD(ROW()-ROW(MinCell),4)*4)
For current year, this is a shorter column B alternative (placed in the workbook just for educational purposes, it's simpler) which I recommend you to replace with any other previous year formula:
=PROMEDIO(DESREF(InventoryList;FILAS(InventoryList)-RESIDUO(FILA()-FILA(MinCell);4)*4;;RESIDUO(FILA()-FILA(MinCell);4)*4;1)) -----> in english: =AVERAGE(OFFSET(InventoryList,ROWS(InventoryList)-MOD(ROW()-ROW(MinCell),4)*4,,MOD(ROW()-ROW(MinCell),4)*4,1))
One advantage is that you can copy down each year block to get the same info for previous years.
I didn't check border condition at the beginning of the year when there're not 4 weeks yet, but that could be (I hope) fixed replacing the expression:
MOD(ROW()-ROW(MinCell),4)*4,1)
by a kinda COUNTIF or something alike. Your homework is to test it with proper data and check what figures you get.
Just advise if any issue.
Regards!
PS: all work ranges (columns E:F aside the table, dates not Friday, totals original contents, and 3 columns C:E aside first totals) can be erased anytime, they're just for clearness and easier understanding of the model.