Moving average ignoring 0

Super_ryan94

New Member
Joined
Sep 6, 2015
Messages
13
Office Version
  1. 2016
Platform
  1. Windows
Hey all,

I could not find an answer that would suit my needs looking on the internet, so hope you can help me on this one.

I have a big table that will have a length of 28800 cells or more with the end containing zeros.
I want to have a moving average of the last 1800 cells not containing any zeros.
If there are less then 1800 cells not containing any zeros, just take the average over the cells within the rules.

The closest formula to suit my needs needed me to type out every cell which I for obvious reasons did not want to do.

What would be the best formula to use for this?

Sincerely, Ryan
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I think this would do the trick if you are referring to cells being in rows.

=IF(NOT(ISERROR(SUM(INDIRECT("A"&MAX(2,ROW(A2)-4)&":A"&ROW(A2)))/(COUNTIF(INDIRECT("A"&MAX(2,ROW(A2)-4)&":A"&ROW(A2)),">"&0)))),SUM(INDIRECT("A"&MAX(2,ROW(A2)-4)&":A"&ROW(A2)))/(COUNTIF(INDIRECT("A"&MAX(2,ROW(A2)-4)&":A"&ROW(A2)),">"&0)),0)


Book3
AB
1ValuesTrailing 4 row Avg
222
332.5
443
503
603
723
812.333333333
952.666666667
1043
1133
1223
1303.5
1403
1502.5
1611.5
1701
1874
1964.666666667
2054.75
2106
2206
2305.5
2405
2500
2600
Super_ryan94
Cell Formulas
RangeFormula
B2:B26B2=IF(NOT(ISERROR(SUM(INDIRECT("A"&MAX(2,ROW(A2)-4)&":A"&ROW(A2)))/(COUNTIF(INDIRECT("A"&MAX(2,ROW(A2)-4)&":A"&ROW(A2)),">"&0)))),SUM(INDIRECT("A"&MAX(2,ROW(A2)-4)&":A"&ROW(A2)))/(COUNTIF(INDIRECT("A"&MAX(2,ROW(A2)-4)&":A"&ROW(A2)),">"&0)),0)
 
Upvote 0
Thanks for the quick reply.

That is not exactly what I was looking for.
I thinking of having all the calculation happen in 1 cell under a sign with average.

Since I have almost 200 columns having the calculation being done in just a since cell would make it easier for me to see everything.

Sincerely, Ryan
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
Thanks for that, how about
Excel Formula:
=AVERAGE(INDEX(A2:A30000,AGGREGATE(14,6,(ROW(A2:A30000)-ROW(A2)+1)/(A2:A30000<>0),ROW(INDIRECT("1:"&MIN(1800,COUNTIF(A:A,">0")))))))
 
Upvote 0
Solution
Book1
ABCDEFGH
1ABCavg Aavg Bavg Cavg Over
2111cells 1-6cells 2-7cells 1-46
3222
4333
5444
6550
7660
8070
9000
10000
Sheet1


Found the add-in \o/

I'm looking for something like this.
 
Upvote 0
Thanks for that, how about
Excel Formula:
=AVERAGE(INDEX(A2:A30000,AGGREGATE(14,6,(ROW(A2:A30000)-ROW(A2)+1)/(A2:A30000<>0),ROW(INDIRECT("1:"&MIN(1800,COUNTIF(A:A,">0")))))))
That does the trick wonderfully easy XD
Thanks you, you solved my problem (y)
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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