Difference from Next Value Analytic Function
This article describes how to use the Difference from Next Value analytic function in CDP Data Visualization.
Click the field on the measurement shelf, in this case, the
sum(population)field on the Y Axis shelf.
In the Field Properties menu, expand Analytic
Functions, and select Difference from Next.
In the Analytic Function: Difference from Next Value modal
- 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 take difference from next value, select year. This is the grouping that applies when calculating the difference from next values.
Under Select the sort order, you can specify the order of sorting. This order specifies what the next row is, and the row where the value is taken. If your visual already specifies sorting order, these values appear in the modal.
You can add additional sort parameters, by clicking the Plus icon.
Here, leave the default order: year ascending, followed by country ascending.
- Under Offset, specify the number of next rows over which the function executes.
- Click Apply.
If you examine the expression in the Enter/Edit Expression
interface, it shows that the function has the following form:
sum([population]) - LEAD(sum([population]), 1) over (partition by [year] order by [year], [country]) as 'diff from next(population)'
- Click Refresh Visual.
Notice the change to the appearance of the visual, and the change in values that appear
on the tooltip.