• took this query from stackoverflow and substituted my values. But, there's no concept of 3 month rolling average.

    ;WITH cte (rn, username, move_in_date, Cnt_Lead_id) AS (

    SELECT

    rn = ROW_NUMBER() OVER (ORDER BY move_in_date),

    username,

    move_in_date,

    Cnt_Lead_id

    FROM [dbo].[countHistory]

    )

    SELECT

    username,

    move_in_date,

    Cnt_Lead_id,

    movagv = (

    SELECT AVG(Cnt_Lead_id)

    FROM cte AS inner_ref

    WHERE inner_ref.rn BETWEEN outer_ref.rn-3 AND outer_ref.rn

    )

    FROM cte AS outer_ref

    ORDER BY username, move_in_date

    If you run this against the sampletable DDL you'll see it doesn't do 3 month rolling.