This article helps you in understanding how to calculate
running average and cumulative average on a given data-set.
As discussed earlier, windowing
functions are the same in SQL Server, Oracle & Hive and perform computations
across a set of table rows that are related to the current row either by the department, area, category, or date/time.
Please observe the sample data-set:
Running Average / Moving Average / Rolling
Average:
The reason to compute a rolling average is to streamline the highs and lows of the dataset and figure out the patterns or trends in the information.
Cumulative Average:
Cumulative or Span of Time is the most common way time is used in a measure. Traditionally Cumulative measures sum data across a span of time.
SELECT DISTINCT Location,YYYYMM, Amount,
AVG(Amount) OVER(ORDER BY Location ROWS BETWEEN 1 PRECEDING AND CURRENT ROW)
AS 'MovingAverage',
AVG(Amount) OVER(ORDER BY Location ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
AS 'CumulativeAverage'
FROM SalesData