• Really not sure if this is what you are after. (No sample results so i cant be sure)

    ;with cte2 as

    (

    select

    [Invoice],

    [D_Type],

    [Status],

    left(datename(month, [RemediationDate]), 3) as Mo,

    year([RemediationDate]) as Yr

    From

    #Remediation

    ),

    cte3 as (

    select D_Type, Status, Yr, Mo, count(*) as #LineItems

    from cte2

    group by grouping sets

    (

    (D_Type, Yr, Mo),

    (D_Type, Yr),

    (Status, Yr, Mo),

    (Status, Yr)

    )

    )

    select *, AVG(#LineItems) over (partition by D_Type, yr, mo)

    from cte3