I had a question from Somnath this week asking what formula he could use to summarise his monthly data into quarters without having to edit the formula for each quarter.
Let’s imagine Somnath is selling ‘things’ and his data looks like this:
And in rows 16:19 he wants to summarise it into quarters by entering a formula in cell B16 and then copying it to the remainder of the table without so much as an F2, or double click to edit any formulas.
Summarise Monthly Data into Quarters
We can achieve this with a dynamic range using the OFFSET function.
If you haven’t come across OFFSET before I recommend you read up on it here with my treasure map example before continuing on.
Ok, let’s take a closer look at the formula in B16:
Remember, the OFFSET function returns a reference to a range that is a given number of rows and columns from a reference. The syntax is:
I’ve crossed out the cols and width arguments as we don’t need them since our range is only 1 column wide.
In my formula the reference argument is the first cell in the table; B2.
The rows argument tells Excel the number of rows, up or down, that we need to move away from the reference to get to the first cell in our range.
Now remember we don’t want to edit this formula for each quarter so we’ve made it calculate the rows argument dynamically incorporating the ROWS function and the strategic use of absolute and relative references.
Now, the ROWS function simply returns the number of rows in a range. Since there is one row in the range B2:B2 our formula evaluates like this:
=SUM(OFFSET(B$2,3*1-3,,3)) which becomes:
In English the above OFFSET formula reads: starting in cell B2 move zero rows down (i.e. start in cell B2) and make the range 3 cells high, which is:
Let’s look at Quarter 2’s formula in cell B17:
Notice how the ROWS formula reference is now B2:B3.
So, the ROWS formula evaluates to 2 since there’s 2 rows in the range B2:B3:
=SUM(OFFSET(B$2,3*2-3,,3)) which becomes:
In English the above OFFSET formula reads: starting in cell B2 move 3 rows down, that’s B5 and make the range 3 cells high. Which is:
Got your months going across columns instead of down rows like the table below?
No problem, you can use this formula which uses the COLUMNS function instead of ROWS:
The COLUMNS function returns the number of columns in a range.
Download the Excel workbook. Note: this is a .xlsx file, please ensure your browser doesn’t change the file extension when you download it.
Check out our Excel Formulas list of free tutorials.
I’d like to thank Somnath for asking this question.
If you liked this please share it with your friends and colleagues using the Google +1, LinkedIn, Facebook and Twitter buttons below.