Beruflich Dokumente
Kultur Dokumente
OFFSET is a difficult one to get the hang of because of the number of arguments involved. Dynamic Arrays Features
You give it a starting point and then you tell it: PowerPoint
Like this:
VIEW CONTENT
One way of getting the average of the last six months, is to use the AVERAGE function. To do that, you
highlight the cells under the Sales column.
However, the problem is that with a dynamic report such as this, there would be new monthly data
coming in after August, and so you would have to manually drag the range of the AVERAGE function
to refer to the most recent six months.
To start, let us go through the OFFSET function on its own before we move on to integrating it in the
AVERAGE function. The syntax of OFFSET is:
You always need a starting point as a reference. Pick any cell that is close to the range that you want
to move around in. In this example, we can select cell B3, which is the column header of the Sales
column.
After that, indicate how many rows you want to move down. Let’s say I want to move down 1 row.
Then specify how many columns you want to move. I want to stay in this column, I will type 0.
The last two arguments are the [height] and the [width]. Writing down 1 for height and 1 for width,
means I want one cell. These last two arguments can never be 0,0. The minimum they can be is 1,1. If
you want to refer to three rows, you’d write 3,1.
For this example, let’s start with using 1,1. My formula at this stage look like this:
=OFFSET(B3,1,0,1,1)
You will notice that the formula’s result is 100. What happens is that it starts at cell B3, and goes down
1 row, then it doesn’t move columns, then it gives us one cell. This gives us 100.
If you set the row parameter to 3, it would move down three rows and give you 130.
=OFFSET(B3,3,0,1,1)
For the column parameter, putting a -1 would move one column to the left and return the date in cell
A6. Using a +1 for the column parameter moves one column to the right and returns a 0 because cell
C6 is empty. This is how OFFSET works.
If we want to use a range instead of a single cell, we would specify a value greater than 1 (or smaller
than -1) for the [height] parameter. Writing the syntax as:
=OFFSET(B3,3,0,3,1)
This results in an error. Why? Let’s track what it’s doing. It starts from cell B3, moves down three cells
to B6 and then it tries to give us cells B6, B7 and B8. However, it can’t actually put these three cells in
one cell.
Whenever the OFFSET function is used in a way where the last two arguments are ranges, and they’re
not just returning one cell but a range of cells, you need to wrap your OFFSET formula in a formula
that can handle ranges. Examples of this would be the AVERAGE, SUM, or the COUNT formula.
In this case, we’re going to use the AVERAGE formula. The function would now be:
=AVERAGE(OFFSET(B3,3,0,3,1))
It results in 108, which is the average of B6, B7 and B8 cells. If we were to expand on this formula to
get the last six months, we have to write the formula differently.
One way is by identifying the last cell in the column using the COUNT function and then use -6 as the
[height], which helps us highlight our range “backwards”.
Another way is to find the last cell, then go back 6 rows and then specify the [height] as +6. It might
seem confusing at the start, so let’s start with the simpler method first.
Start by using cell B3 as your reference. How many cells should we move down? Use the COUNT or
COUNTA function to count the number of filled cells that we have in the Sales column right below B3.
In this case, it doesn’t matter if we use the COUNT or the COUNTA function.
Using the COUNT function, we highlight the cells under B3. It’s essential to highlight more cells than
what you’re currently using, because you want to take into account new data that will be added in the
future. The formula would now be:
=AVERAGE(OFFSET(B3,COUNTA(B4:B15),0,-6,1))
Now, when we add data for a new month on cell B11 – let’s say, 200 – the formula automatically
updates to an average of 127, which we can check by comparing it to the average displayed on the
status bar when cells B6 to B11 are highlighted.
We can also check this by going to Formulas > Evaluate Formula, and then click on the Evaluate
button. You will see that the final range that it’s taking is the average of B6 to B11, which is what we
intended.
=AVERAGE(OFFSET(B4,COUNT(B4:B14)-6,0,6,1)
This results in 127 as well. These are two different ways of writing the formula.
Let’s take another example where the data is arranged in a horizontal manner.
To perform the same computation, we follow a similar approach. We start with the AVERAGE function
followed by the OFFSET function. We write it as:
=AVERAGE(OFFSET(A17,0,COUNT(B17:O17),1,-6))
This achieves the same as getting the average of the last six months from July. If we again add data for
August, it automatically updates to include August and then computes the average of the last six
months. This results in 127.
Just be creative and practice this in all directions until you get the hang of it.
To perform this computation, we’re going to do the same thing by using the AVERAGE function
together with OFFSET.
For the row, we want to move down the number of cells to arrive at the selected month that the user
picked from the drop-down. The MATCH function would give us the position of the selected month in
the data table.
For example, if the selected month is 04/2014, which corresponds to 90, the formula needs to find the
position of 90 in the data table, which is the fourth row. To use the MATCH() function, the syntax is:
We refer to the drop-down cell, F25, as the lookup_value, and the Month column A26:A51 as the
array. [match_type] is set 0 for a perfect match. The formula will read:
=MATCH(F25,A25:A51,0).
This would count the position of the selected month. In the case of 04/2014, it results in 4.
[Height] depends on the question. If we want to include the selected month in the computation, we
would use a 3.
[Width] is set to 1 .
=AVERAGE(OFFSET(B25,MATCH(F25,A26:A51,0),0,3,1)
If we do not want to include the selected month in the computation, we have to add a +1 to our
MATCH function. This tells the formula to find this selected month and go down one extra cell. The
final formula becomes:
=AVERAGE(OFFSET(B25,MATCH(F25,A26:A51,0)+1,0,3,1)
The average yields 113, which is the average of the three months after the selected month, i.e.
average of B30:B32.
This is completely dynamic so if you were to select December 2014, you would get an average of 232
for the three months after this month.
This is how you can use the AVERAGE function, the OFFSET function, and the MATCH functions all
together to create this dynamic effect in your Excel files.
Caution!
A word of caution is that the OFFSET is a volatile Excel formula, which means it calculates every time
you make a move in Excel. To be honest, in the files that I’ve used OFFSET in, I’ve hardly experienced
my files becoming slow because of using this function. But I also didn’t overdose on them. I
recommend that you don’t overuse them.
Unbeatable value!
LEARN MORE
11 Comments
I use OFFSET and Define Name to dynamically track the most recent 5 test results on a
spreadsheet that expands over time… and that data is fed to rolling charts.
=OFFSET(‘Test Results’!J6,1,COUNTA(‘Test Results’!$I$5:$DD$5)-5,1,-1)
The problem I run into is when entering the first few results. Any time there are less columns
(or rows) with data than you have indicated in your OFFSET formula, the formula will
reference irrelevant cells or produce errors if it runs out of columns (or rows).
For example, if my OFFSET is set to -5 (columns), but I only have 2 or 3 columns of data, my
Offset formula will still try to reference 5 columns… so it will end up referencing column titles
or whatever is to the left of my starting reference, or it will produce an error because there
are no more columns remaining on the spreadsheet.
Should I be using INDEX instead? Or maybe there’s some kind of parameter that tells OFFSET
to stop at a specified column, or mixing in an IF, THEN formula? I feel like I’m missing
something simple:/
Hi – Yes you can use INDEX or stick with OFFSET and use an IF. Depending on what you
want returned, here are some options:
=INDEX($J$7:$DD$7,,IF(COUNTA($I$5:$DD$5)-5>0,COUNTA($I$5:$DD$5)-5,0)) which
returns 0 if the count is below 5 or with offset
you can use this formula for the column argument:
IF(COUNTA($I$5:$DD$5)-5>0,COUNTA($I$5:$DD$5)-5,ABS(COUNTA($I$5:$DD$5)-5)) or:
IF(COUNTA($I$5:$DD$5)
<5,CHOOSE(COUNTA($I$5:$DD$5),1,2,3,4),COUNTA($I$5:$DD$5)-5) for the column
argument. It depends on what you want returned if the value is below 5.
Awesome!! I used a similar version of OFFSET and added a couple MIN/MAX COLUMNS
parameters. I’m also going to check out the INDEX option too, just as a less volatile
approach. REEEEaally appreciate the info:))
I use the offset function to show the most recent 12 weeks of data on my graphs but there is
one recent week where we literally don’t have any data. I want to leave the cell blank but still
include it in the cell count which would result in one missing data point on my graph. The
COUNT and COUNTA functions won’t allow that and COUNTBLANK only counts the blank
cells when I need to count all the cells which from the past 12 weeks which includes 11 cells
with numbers and 1 blank cell (the missing data point). Is there a way to use the COUNTIF
function to count both blank cells and cells containing data or do you have any other advice?
How about using countif with wildcards to find at least one character similar to what I
show in this video: https://youtu.be/7fYlWeMQ6L8 Fast forward to 12:20.
You might also find the video interesting if you want to skip blanks in your chart:
https://youtu.be/lQG-g6_noPc
Hope this helps.
Hi Leila,
What is the difference between offset and index? Is there anything offset can do that index
can’t? If no, why would anybody want to use offset instead of index when it is know that
offset is more volatile and can slow down larger files?
PS: I’m using offset for dependent drop-down lists (source list is dynamic, adding rows of
data up to 10 times a month), but would definitely change it to index if possible.
Thanks,
Ben
Hi,
I work with financial performance data and for calculating inception performance I need
inception count.
I wanted to find out whether I am able to insert an offset function that will automatically
include new entries when I populate performance on a monthly bases while still fixing the
inception cell.
For example
With a count formula, I can have
Count (#B3:BF3) to fix the inception column B, which is fine. But this will require an update
everytime new data is populated-eg, if an extra month of performance is added, reference
BF3 will have to be updated to BG3.
, I figured an offset function could be more efficient as the formulas automatically update to
include new data, however, I don’t know how to fix the inception reference B3, and still have
the formula updating to BG3.
Leila, do you have examples where you use the OFFSET function to create a dynamic range
name?
Thank you so much for all your amazing work! As a trainer teaching Excel for over 30 years, I
wish I had someone like you as I developed my skills.
Cheers!
Joy
Hi Joy – Thank you! I’m glad you enjoy the tutorials. You’ll find an example of offset in
name manager in this video. Towards the end, where I create the dependent drop
down. I try to use the INDEX formula instead wherever I can, as INDEX is not volatile.
It is very needed to be a professional at least in one of Microsoft office programs. Your post
is very useful for beginners in this matter. Excel is very hard to learn program.
Wow. This function is really useful. I often use this program, especially in the learning
process. And the offset function allows you to save time to fill the data. Fine.
Leave A Comment
Comment...
Name (required)
Email (required)
Website
Save my name, email, and website in this browser for the next time I comment.
POST COMMENT
Subscribe to my Newsletter | Copyright 2018 XelPlus.com | All Rights Reserved | Impressum | Privacy Policy