Moving average analytic function
This article describes how to use the Moving Average analytic function in CDP Data Visualization.
Click the field on the measurement shelf.In this example, the
sum(population)field on the Y Axis shelf.
In the FIELD PROPERTIES menu, expand Analytic
Functions, and select Moving Average.
In the Analytic Function: Moving Average modal window:
In Select aggregate for this measure, leave the default Sum. The other aggregation options are Count, Minimum, Maximum, and Average. In addition, some connection types also support Approximate Distinct Count and Exact Distinct Count.
Under Select entities over which to calculate moving averages, select year. This is the grouping that applies when calculating the moving average.
Under Select the sort order, you can specify the order of sorting. This order specifies what the row is, and the row where the value is taken. If your visual already specifies sorting order, these values appear in the modal.
In this example, leave the default order: year ascending, followed by country ascending.
Under Rows to include in the average (relative to current row), the options for leading rows are: All previous rows, Current row, or Previous row(s) (default). Select the last option, then specify the number of preceding rows for the calculation; the default is 5, but we changed it to 2.
Similarly, the options for following rows are: All forward rows, Current row (default), or Forward row(s). Select the last option; the default is 5, but we changed it to 2.
- Click APPLY.
If you examine the expression in the Enter/Edit Expression
interface, it shows that the function has the following form:
avg(sum([population])) over (partition by [year] order by [year], [country] rows between 2 preceding and 2 following) as 'moving average(population)'
Click REFRESH VISUAL.
You can see the change to the appearance of the visual, and the change in values that appear on the tooltip.