Since most of Excel Formula requires a range, for example
=AVERAGE(Range to average)
Sometime it is hard to pass customized range into it, for example, A1:A5 in the formula in row 3, but A6:A10 in the row below, row 4.
And in cases like that, functions such as OFFSET (Where you "Shift" the range by certain rows, columns, basing on calculation, for example, for every row below the first formula, you shift x amount of rows down, y amount of columns to the left / right), or a more powerful one in my opinion, INDIRECT (Where you construct the range directly and pass it to the formula).
For example, starting from row 3, B3, you want to calculate the average of every 5 cells, so in Row3, it's A3:A7, in Row4, it's A8:A12, so on and so forth.
First, you will have to find a formula that, for every row down, it gives you a number that's 5 times that value (Since we are averaging 5 values at a time, right?) - which I immediately think of ROW(), the formula that returns the row number of the row it's on.
So I wanted to return a value of 3 on Row3, 8 on Row4, and 13 on Row5, thus I use
=(ROW()-ROW($B$3))*5+ROW($B$3)
On Row3, ROW() returns 3, ROW($B$3) returns 3, so the equation returns (3 - 3)*5 + 3 = 0 * 5 + 3 = 0 + 3 = 3, perfect
On Row4, ROW() returns a 4, ROW($B$3) returns a 3 (the row number of cell B3), so the equation returns (4 - 3) * 5 + 3 = 1 * 5 + 3 = 8
On Row5, ROW() returns a 45 ROW($B$3) returns a 3 (the row number of cell B3), so the equation returns (5 - 3) * 5 + 3 = 2 * 5 + 3 = 13
And you get the idea. You might wonder about ROW($B$3) - The very first row that the formula starts is 3, thus $B$3 (The $ sign is to prevent the reference from changing when you drag the formula left / right) - So if you want the formula to start on row 5 instead, change $B$3 to $B$5
What about when you want to calculate every 7 rows instead? Simply change *5 to *7
And right now, you can use the OFFSET formula like this
And it will return the average of 5 rows, depending on the row it is on. Here's why:
The format of OFFSET is OFFSET(range, rows, column) (there are 2 more at the end, optional, with are height and width, you can look them up later)
So let's say you wanna calculate every 5 rows, that's perfect, let's set our original range to A1:A5, and remember the ROW() formula above giving the value 3 in the 3rd row? What would happen if you shift the range A1:A5 3 rows down, 0 column?
It will become A4:A8.
How about only shift it 2 rows down? A3:A7 - perfect (hence the -1 you see in the formula)
What about INDIRECT? In order to use INDIRECT, you have to construct and put together the range as text string - from letter to letter, so in order to put together a text like "A3:A8" this is what I do
"A" & (ROW()-ROW($B$3))*5+ROW($B$3) & ":A" & (ROW()-ROW($B$3))*5+ROW($B$3)+4
On Row3, this formula returns:
"A" & 3 & ":A" & 3+4 = "A3:A7"
And to put it into AVERAGE:
I'm sorry I'm bad at this, but I tried, and if you have any question, don't hestitate to ask me ok xd
If your Data starts at A3, from Column A to D for example, and you wanna see how the parts of the formula is working, in these cells, paste these formula in:
E3:
F3:
G3:
H3:
And drag them down until you start seeing #DIV/0 - You run out of range to calculate (Excel please, still can't average a bunch of 0)
Bookmarks