where n=5 because each week contains 5 rows of data.
Calculating ranges
The OFFSET function returns a reference to a range constructed with five inputs: (1) a starting point, (2) a row offset, (3) a column offset, (4) a height in rows, (5) a width in columns. In the example shown, we use OFFSET inside of SUM like this: The starting reference is C5, since this is the first value in the data. Notice we use an absolute reference because we don’t want this reference to change later when we copy the formula down. The next argument, rows, is the crux of the problem because this is where we need logic that will figure out the correct starting row for each week. To calculate the right starting point, we use the ROW function. ROW returns the row number for a given reference or, if no reference is provided, the row number of the cell containing the formula. Because the formula sits cell F4, ROW() will return 4. We use this fact to create the logic we need. We first subtract 4 as an “offset” because we want to create a zero-based index, for reasons made clear below. Then we multiply the result by 5, this is how this snippet will evaluate in cells F4, F5, and F6: To finish off the arguments for OFFSET, we provide cols as zero, because we want to stay in the same column. We provide height as 5 because we want a range that contains 5 rows. Finally, we provide width as 1, because we want a range that contains 1 column. After the row logic runs, this is how OFFSET works F4, F5, and F6:
Summing ranges
The final step in the problem is just to sum the ranges provided by OFFSET. This is done with the SUM function. After OFFSET is evaluated, the resulting range is delivered directly the SUM function, which sums the values in the range and returns a final result. As the formula is copied down into F4:F6, we get the final totals per week: To recap: OFFSET returns a calculation of the correct range for each week using the row logic explained above. The SUM function sums the ranges returned by OFFSET.
Dave Bruns
Hi - I’m Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.