moving average for missing months SQL 2008

  • I am trying to determine the moving average month over month for missing months and have fallen into a whole. Example in excel =AVERAGE(H2:H7) the next cell under it(if you copy paste) is =AVERAGE(H3:H8). This is more of rolling average with shaping. i am trying to replicate this in SQL but have come across an issue. If (for example) months 1-5 are not populated they will not get populated at all. Issue 2 is that I for some reason can not get the calculate correct. here is an example data set:

    number MTHdata

    10089010001464900161008277

    10089010001464900161006256

    10089010001464900161009256

    100890100014649001610011240

    10089010001464900161007235

    100890100014649001610010178

    100890100014649001610010

    100890100014649001610020

    100890100014649001610030

    100890100014649001610040

    100890100014649001610050

    1008901000146490016100120

    since there are 6 records in this set i need to get the average of those six and populate month 1, then i need to take the records of 6,9,1,7,10,1 and get the average and populate month 2 etc. Any assistance would be great. Thank you.

  • Moving average in TSQL

    http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=93911

  • I have read the article but none of the solutions resolve when a previous months value is 0, i need to recalculate the rolling average

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply