Calculating an averags for a dynamic range between zeros

grantjw

New Member
Joined
Dec 17, 2012
Messages
12
I have a column of numbers representing each hour in a month (720 or 744 rows). I need to find the average of consecutive number blocks that fall between zero values. The block can be as small as two numbers or it could be as large as the whole month (no zero values in the column).

For example take a column of numbers 10,5,0,0,3,5,6,7,0,2,5,4,3,4. So I would need to find the average of the first block 10,2 then skipping 0,0 find another average of the next block 3,5,6,7, then skip 0 and find the average of the next block 2,5,4,3,4 and so on.

Any help would be appreciated. Thanks!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I've split this into three calculations for simplicity but you might be able to combine them.
Assume your data is in column A with a heading in row 1.
In cell B2 put the following formula: =IF($A2=0,0,IF(ISNUMBER($B1),$B1,0)+$A2)
In cell C2 put the following formula: =IF($A2=0,0,IF(ISNUMBER($C1),$C1,0)+1)
and in D2 put the following formula: =IF(C2=0,"",IF(C3=0,B2/C2,""))

Column B total each set of numbers
Column C counts the elements
Column D shows the averages

Hope this helps
 
Upvote 0
I've split this into three calculations for simplicity but you might be able to combine them.
Assume your data is in column A with a heading in row 1.
In cell B2 put the following formula: =IF($A2=0,0,IF(ISNUMBER($B1),$B1,0)+$A2)
In cell C2 put the following formula: =IF($A2=0,0,IF(ISNUMBER($C1),$C1,0)+1)
and in D2 put the following formula: =IF(C2=0,"",IF(C3=0,B2/C2,""))

Column B total each set of numbers
Column C counts the elements
Column D shows the averages

Hope this helps

You Feedback was extremely helpfull!
The Average for the first block 10,5 was not calculating correctly. I had to add
In Cell B1 put the following formula: =IF($A1>0,$A1,0)
In Cell C1 put the following formula: =IF($A1>0,1,0)

It works perfectly. Thanks to you and many others on this site who volunteer their knowledge. This will save many wasted hours on cut and copy operations!


JWG
 
Upvote 0

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

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