The MOD is used to determine where in the recurring "chunk" of 40 rows the current row resides ... this result will be 0-39
(eg Row 1 being 0, Row 10 being 9 and Row 40 being 39 and all other numbers in between)
We know that we wish to conduct Avg calcs of one sort or another every 10th (mod 9) and 40th (mod 39) row within the dataset - for all other rows we simply want to return a Null.
To work this out I opted to push the Mod return into a Match
MATCH(mod result,{0,9,10,39})
the above will return a value between 1-4 depending on where the current Mod value is placed in terms of the value within the Match inline array, eg:
00-08: 1
09: 2
10-38: 3
39: 4
We then use the above value in a CHOOSE to establish the appropriate action to take - if the MATCH returned either 1 or 3 we want to return a Null - if 2 or 4 we need to perform an avg calc, eg:
CHOOSE(match result,"",avg1,"",avg2)
The Average calcs themselves are virtually identical except for their starting points, eg:
avg1: AVERAGE(INDEX($A:$A,ROW(B1)-9):$A1)
avg2: AVERAGE(INDEX($A:$A,ROW(B1)-29):$A1)
we know avg1 range should be 10x1, ie 9 rows prior and current row
we know avg2 range should be 30x1, ie 29 rows prior and current row
So in terms of overall workflow:
1 - establish Mod of range to determine 10th and 40th rows in each block
2 - use Match to determine which action to take pending Mod return
3 - use Choose in conjunction with 2 to identify said action
4 - use Index within Average to establish the appropriate range to Average (based on which row is being calculated - ie 10th/40th)
I hope that helps.
Bookmarks