Moving average last 5 numeric number, N/A for any zero cells and the omitting that for next moving average

ttngu17

New Member
Joined
Jul 18, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello,
I have been trying to find the formula that will work for the finding the moving average of the last 5 numeric number , for those that have "0" value would be "N/A" and that "0" would be excluded from calculating the next moving average.
Below is the table that i'm working on. I'm able to get to the following formula where it calculate moving 5 correctly, but after there is a zero entry it includes the 0 in its calculation where I would like to skip it . For example on row 11 I would like it to calculate the average of row 11,9,8,7,6

Current formula I have is
=IF(A6<=0,NA(),AVERAGE(OFFSET(A6,0,0,-5,1)))

Any help would be much appreciated. Thanks so much in advance.

1​
Data5 days moving average
2​
1158150.93​
3​
1371140.64​
4​
944049​
5​
1143291.87​
6​
1657468.86​
1254820​
7​
1433896.28​
1309969​
8​
1634534.82​
1362648​
9​
2160770.04​
1605992​
10​
0​
#N/A​
11​
1903487.21​
1426538​
12​
1709663.66​
13​
1394217.07​
14​
1253709.87​
15​
1183419.02​
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try:
Book2
AB
1Data5 days moving average
21158150.931158150.93
31371140.641264645.785
49440491157780.19
51143291.871154158.11
61657468.861254820.26
71433896.281309969.33
81634534.821362648.166
92160770.041605992.374
100#N/A
111903487.211758031.442
121709663.661768470.402
131394217.071760534.56
141253709.871684369.57
151183419.021488899.366
Sheet3
Cell Formulas
RangeFormula
B2:B15B2=IF(A2:A15=0,NA(),MAP(A2:A15,LAMBDA(m,AVERAGE(TAKE(FILTER(A2:m,A2:m<>0),-5)))))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,080
Members
453,021
Latest member
Justyna P

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