View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
[email protected] joeu2004@hotmail.com is offline
external usenet poster
 
Posts: 418
Default Calculate a 30-day moving average based on the last x number of entries and date

gimiv wrote:
Hello, I have a worksheet that has all weekday dates in column 1 and
values in column 2. I want to create a 30-day moving average based on
the last (non-zero) value in the column 2. Since every month has a
different amount of days, I want it to search the date that has the
last value (since I don't get a chance to update it daily) and go back
thirsty days from that date and give an average of all the column 2
values skipping and values that are null or zero.


The solution might be a lot simpler than you might think. But your
description leaves me with several questions, so I am not sure. Does
the following paradigm work for you?

Assume your data starts in B2. The first 30 days of data are in
B2:B31, some cells of which might be zero presumably because you "did
not get a chance to update it daily". It appears that you want the
following average, entered into C31 perhaps:

=sumif(B2:B31,"<0") / countif(B2:B31,"<0")

If you copy that down the column, the range will automatically be a
moving 30-day period; for example, B3:B32, B4:B33, etc. Thus, it
creates a trailing simple moving average, ignoring cells with zero.