• Where's the PARTITION BY Company part of your query? PARTITION BY is analogous to GROUP BY... and it seems to be missing, so the totals/counts won't "restart" when the Company changes.

    Should it not be... Note the "PARTITION BY Company" in both calculations

    SELECT Company

    ,[Revenue Year]

    ,[Revenue Amount]

    ,CASE

    WHEN COUNT(*) OVER (

    PARTITION BY Company

    ORDER BY Company

    ,[Revenue Year] ROWS BETWEEN UNBOUNDED PRECEDING

    AND CURRENT ROW

    ) > 2

    THEN AVG([Revenue Amount]) OVER (

    PARTITION BY Company

    ORDER BY Company

    ,[Revenue Year] ROWS BETWEEN 2 PRECEDING

    AND CURRENT ROW

    )

    ELSE NULL

    END ThreeMonthRunningAvg

    FROM YHL.NAICS_Company_Revenue

    ORDER BY 1

    ,2