Difference from previous value analytic function

This article describes how to use the Difference from Previous Value analytic function in CDP Data Visualization.

  1. Click the field on the measurement shelf.
    In this example, the sum(population) field on the Y Axis shelf.
  2. In the FIELD PROPERTIES menu, expand Analytic Functions, and select Difference from Previous.
  3. In the Analytic Function: Difference from Previous Value modal window:
    1. 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.

    2. Under Select entities over which to take difference from previous value, select year. This is the grouping that applies when calculating the difference from previous values.

    3. Under Select the sort order, you can specify the order of sorting. This order specifies what the previous 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.

    4. Under Offset, specify the number of previous rows over which the function executes.
  4. Click APPLY.
  5. Optional: If you examine the expression in the Enter/Edit Expression interface, it shows that the function has the following form: sum([population]) - LAG(sum([population]), 1) over (partition by [year] order by [year], [country]) as 'difference from previous value(population)'
  6. Click REFRESH VISUAL.
    You can see the change to the appearance of the visual, and the change in values that appear on the tooltip.