average(if()) question

agpj

New Member
Joined
Aug 3, 2010
Messages
6
I have a list similar to the following in column A:

A
98
15
0
315
223
145
62
0
329
216
101
98
0
310
198
96

As you can see, the numbers jump and wane cyclically. I want to find the averages of all the "jumps." In this case, the average of 315, 329, and 310. Is there a way I can write an average-if function (preferrably sans VBA) that averages all the numbers after every instance of 0?

Thanks
pj
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Perhaps

=AVERAGE(IF(A2:A100>A1:A99,A2:A100)) 'Notice the offset - it's intentional.

CTRL + SHIFT + ENTER
 
Upvote 0
njimack and jonmo1,

your solutions worked perfectly, thanks! I don't understand the logic behind your formulas though...would you mind running through it? Are the ranges basically for-loop equivalents?
 
Upvote 0
njimack and jonmo1,

your solutions worked perfectly, thanks! I don't understand the logic behind your formulas though...would you mind running through it? Are the ranges basically for-loop equivalents?

That's an interesting way to look at it, yes it does do a kind of loop.

Both our formulas are essentially the same, but using different criteria.

njimack used =0, where I used Greater Than..

Use njimack's if it's always resetting to 0
Use mine if it's more like when the number goes down any amount, instead of up.

So taking njimack's
=AVERAGE(IF(A1:A15=0,A2:A16))

It does do a loop of every cell in A1:A15.
But it's not technically using a Row#, it's using the POSITION # in the array A1:A15.

So first loop looks at the first position of A1:A15 (A1).
Does that = 0, if it is, it then adds the value in the first position # of A2:A16 (A2)

2nd loop looks at the 2nd position of the array A1:A5 (A2)
Does that = 0, if it is then it adds the value of the 2nd postion of A2:A16 (A3)

And so on.

Hope that helps..
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top