add_moving_average
Add a new field to the data extract with moving averages.
Introduction
Use the add_moving_average enrichment to add a new field to the data extract which calculates the moving average for a specific number of values. Moving averages are calculated with the formula (value_in_current_row + values_in_previous_N_rows + values_in_next_N_rows) / (2 * N + 1)
where N
is the number you specify in the Window Size field. The first and last N rows in the new field are left empty.
Creating the enrichment
For more information on creating an enrichment, see Using custom scripts.
Configuring the enrichment
To configure the enrichment, fill in the following fields. Required fields are marked with an asterisk (*).
-
Field
-
Specify the field which contains the original values.
-
Window Size
-
Specify the number of values before and after the current row to use for calculating moving averages.
-
New Fieldname
-
Specify the name of the new field to add to the data extract.
-
Subtable
-
Enter the name for a subtable that you want to contain the enriched data. The enrichment is applied to the whole data extract, then the enriched data is output into the subtable you have named here.
This subtable is a temporary table, which means it 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.
Example
Enrichment configuration
-
Field
-
Clicks
-
Window Size
-
1
-
New Fieldname
-
Clicks_Moving_Average
Data table before enrichment
Date |
Clicks |
---|---|
2021-11-01 |
7 |
2021-11-02 |
3 |
2021-11-03 |
18 |
2021-11-04 |
9 |
Data table after enrichment
Date |
Clicks |
Clicks_Moving_Average |
---|---|---|
2021-11-01 |
7 |
|
2021-11-02 |
3 |
14 |
2021-11-03 |
18 |
15 |
2021-11-04 |
9 |
|