Hi Shawn,
Since you are trying to do a moving avg of a cumulative total you could also do this in your query using CTEs.
Take this example of the 50 most recent BMIS:
with CTE AS
(select top 50 vs.date, vs.BMI
from vital_signs as vs
where bmi is not null
order by vs.date desc),
CTE2 AS (
Select *,
SUM(BMI) over(order by vs.date desc) Cumulative_Total
from CTE)
Select *,
Avg(Sum(Cumulative_Total)) Over (Order By vs.date desc Rows Between 49 Preceding and Current row) as ‘Cumulative Moving Avg’
from CTE2
group by vs.date, BMI, Cumulative_Total
order by vs.date desc
Derek