Moving Average for previous 2 days, current day, and 2 days after

johnsonlnl29

New Member
Joined
Feb 25, 2014
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi -
I'm stuck and hoping someone here can assist. I'm working in Excel 365 with a table. I'm trying to find the 5 day average for previous 2 days, current day, and 2 days after. Example: for December 5 I would like Dec 3, 4,5,6,7 data to calculate my 5 day average. In addition, for days that don't have the 2 days after yet I'd like it to be #N/A until the data is there. This is a table that is updated daily via Power Query from an ACCESS query. If it's easier to do in ACCESS I could do that too it's just right now I'm doing these types of calcs in the Excel table. I'd prefer non VBA if possible as I'm not real strong in that area of Excel. I appreciate any and all help!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Since you haven't shared any data, I can only tell your solution is AverageIFS nested in IFS function.
 
Upvote 0
As @SanjayGMusafir pointed out, some data would have been useful, and I agree with him that an IF/Averageif combination might be the way to go. There's probably a more elegant solution than this but here's one suggestion anyway:
Book1
ABCDEFGHIJ
1Date7-Dec-238-Dec-239-Dec-2310-Dec-2311-Dec-2312-Dec-2313-Dec-2314-Dec-23Average
2Values 11234564
3Values 212345#N/A
Sheet1
Cell Formulas
RangeFormula
J2:J3J2=IF(OR(INDEX(B2:I2,MATCH(TODAY()+1,$B$1:$I$1,0))="",INDEX(B2:I2,MATCH(TODAY()+2,$B$1:$I$1,0))=""),"#N/A",AVERAGEIFS(B2:I2,$B$1:$I$1,">="&TODAY()-2,$B$1:$I$1,"<="&TODAY()+2))
 
Upvote 0
Welcome to the MrExcel board!

I'm working in Excel 365
Please add that to your forum profile (click your user name at the top right of the forum, then ‘Account details’) 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’)

Is this the sort of thing you are after?

23 12 10.xlsm
ABC
1DateValue5 day moving average
201-Dec-2370 
302-Dec-2323 
403-Dec-23845.6
504-Dec-237740.4
605-Dec-235039
706-Dec-234455
807-Dec-231643.4
908-Dec-238838.4
1009-Dec-2319#N/A
1110-Dec-2325#N/A
1211-Dec-23#N/A
1312-Dec-23#N/A
Moving average
Cell Formulas
RangeFormula
C2:C13C2=IF(COUNT(A$2:A2)>2,IF(B4<>"",AVERAGE(INDEX(B:B,SEQUENCE(5,,ROW()-2))),NA()),"")
 
Last edited:
Upvote 0
Solution
Hello -
Yes! @Peter_SSs you nailed it! :)
I made note next time to include a data set as example.
I updated my profile as noted.
Thanks again everyone ~
Angie
 
Upvote 0
You are welcome. Thanks for the follow-up. :)

.. and thanks for updating your profile. (y)
 
Upvote 0

Forum statistics

Threads
1,215,077
Messages
6,122,991
Members
449,094
Latest member
masterms

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