increment
Sort a data extract and add a new column containing a difference in values.
This guide explains how to configure the increment instruction. To learn about another instruction, go back to the Available custom script instructions overview.
Introduction
Use the increment instruction to sort a data extract based on given column names and a column containing numerical values. Once sorted, a new column is added to the data extract containing the numerical difference between the value in the current row and the value in the previous row.
This enrichment is similar to the sumup enrichment. The increment enrichment calculates the difference between rows and the sumup enrichment calculates the sum total of rows.
To use the increment custom script instruction, the values used in the instruction must be in numeric format. If necessary, use the convertnumbers custom script instruction to convert string values to a numeric format. Add the convertnumbers instruction to the same custom script enrichment before the increment instruction.
Creating a custom script enrichment using the increment instruction
To create and configure a custom script using the increment instruction, follow these steps:
-
In the Instructions step, select the increment instruction.
-
To configure the custom script instruction, fill in the following fields. Required fields are marked with an asterisk (*).
-
Input Field*
-
Enter the field that contains the numeric fields which the enrichment will sort and from which the enrichment will calculate the difference.
-
Output Field*
-
Enter the name of the new column which contains the calculated differences.
-
Keys
-
Enter the names of the columns to sort. You can enter the names of multiple columns. Every new unique combination of Key fields will reset the difference calculation to 0.
-
Subtable
-
Enter the name for a subtable that you want to use within this custom script.
A subtable is a temporary table that only exists for this custom script. You can apply additional instructions within the same custom script to the subtable. However, the subtable cannot be used in any other custom scripts.
If a subtable does not exist for the current custom script, the enrichment is applied to the data extract, and the enriched data is output into the subtable. If the subtable already exists for the custom script, the subtable is used as the input for the enrichment and optionally as the output.
Example
Enrichment configuration
-
Input Field*
-
Clicks
-
Output Field*
-
Click Difference
-
Keys
-
Campaign
-
Ad Group
Data table before enrichment
Date |
Campaign |
Ad Group |
Clicks |
---|---|---|---|
2022-06-20 |
Brand |
ecommerce |
7 |
2022-06-20 |
Brand |
socials |
3 |
2022-06-20 |
Dashboard |
ecommerce |
18 |
2022-06-21 |
Brand |
ecommerce |
4 |
2022-06-21 |
Brand |
social |
6 |
2022-06-21 |
Dashboard |
ecommerce |
5 |
2022-06-22 |
Brand |
ecommerce |
11 |
2022-06-22 |
Brand |
social |
45 |
Data table after enrichment
Date |
Campaign |
Ad Group |
Clicks |
Click Difference |
---|---|---|---|---|
2022-06-20 |
Brand |
ecommerce |
7 |
7 |
2022-06-21 |
Brand |
ecommerce |
4 |
-3 |
2022-06-22 |
Brand |
ecommerce |
11 |
7 |
2022-06-20 |
Brand |
socials |
3 |
3 |
2022-06-21 |
Brand |
social |
6 |
3 |
2022-06-22 |
Brand |
social |
45 |
39 |
2022-06-20 |
Dashboard |
ecommerce |
18 |
18 |
2022-06-21 |
Dashboard |
ecommerce |
5 |
-13 |
The thick border lines in the table above will not appear in your data extract after the increment enrichment. The thick border lines have been added to highlight where the difference calculation resets and how the data extract is sorted.