30 day Moving Average

Gusher

Board Regular
Joined
Aug 21, 2011
Messages
199
Hi

In Col A I have dates but Saturday and Sunday are excluded i.e only weekdays. I have date for several years.

In Col B I have prices.

In col C I wish to calculate the 30 day moving price average WITH weekend included in the 30 day count.

Any suggestions please?

Best Regards

Mark
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi Mark,

My solution to your problem needs some helper columns.


I am calculating avg for 7 days, you can change it to 30 wherever you see in my formula.

Enter the following formula in C1 and copy it down

=1+IF(WEEKDAY(A1)=6,2,0)

Enter the following formula in D1 and copy it down

=CEILING(SUM($C$1:C1),7)

Finally enter the following formula in E1 and copy it down

=IF(IF((MOD(SUM($C$1:C1),7))=0,SUM($C$1:C1),"")<>"",SUMIFS(B:B,D:D,D1)/7,"")

1613133210739.png


Kind regards

Saba
 
Upvote 0
@Gusher
Am I correct in thinking that in calculating your 30 day average you are wanting the non-recorded Saturdays and Sundays to be considered to be holding the value of the previous Friday?

If so then try the following formula in column C.
Enter it at row 22 and drag down as required. In rows 1-21 it will return an error.

VBA Code:
=(SUMIF(A1:A22,">="&A22-29,B1:B22)+SUMPRODUCT((WEEKDAY(A2:A22,2)=1)*(B1:B21)*2)-IF(WEEKDAY(A22,2)=1,WEEKDAY(A22,2)*B1,0))/30

Hope that helps
 
Upvote 0
Hi Mark,

My solution to your problem needs some helper columns.


I am calculating avg for 7 days, you can change it to 30 wherever you see in my formula.

Enter the following formula in C1 and copy it down

=1+IF(WEEKDAY(A1)=6,2,0)

Enter the following formula in D1 and copy it down

=CEILING(SUM($C$1:C1),7)

Finally enter the following formula in E1 and copy it down

=IF(IF((MOD(SUM($C$1:C1),7))=0,SUM($C$1:C1),"")<>"",SUMIFS(B:B,D:D,D1)/7,"")

View attachment 31917

Kind regards

Saba
Many Thanks Saba, that worked.
 
Upvote 0
@Gusher
Am I correct in thinking that in calculating your 30 day average you are wanting the non-recorded Saturdays and Sundays to be considered to be holding the value of the previous Friday?

If so then try the following formula in column C.
Enter it at row 22 and drag down as required. In rows 1-21 it will return an error.

VBA Code:
=(SUMIF(A1:A22,">="&A22-29,B1:B22)+SUMPRODUCT((WEEKDAY(A2:A22,2)=1)*(B1:B21)*2)-IF(WEEKDAY(A22,2)=1,WEEKDAY(A22,2)*B1,0))/30

Hope that helps
Many thanks Sankehips
 
Upvote 0

Forum statistics

Threads
1,215,562
Messages
6,125,546
Members
449,237
Latest member
Chase S

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