addfieldx

Add a new field to the data extract with values calculated using a Python expression.

Introduction

Use the addfieldx enrichment to add a new field to the data extract with values calculated using a Python expression.

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 Name

Specify the name of the new field to add to the data extract.

Python Expression

Specify the formula used to calculate the new values. Write this formula as a one-line Python expression. To use values in the same row as the current row but from different columns, surround the column name in curly brackets ({}). For example, {dimension_a} + '_' + {dimension_b} or ({metric_1} + {metric_2}) / 100.

Field Index

Specify where to add the new field in the data extract. To add the field to the first position, specify 0. To add the field to the last position, specify -1.

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 Name

Campaign and Ad Group

Python Expression

{Campaign} + '_' + {Ad Group}

Field Index

-1

Data table before enrichment

Campaign

Ad Group

Clicks

Brand

media

7

Brand

ecommerce

3

Dashboard

media|social

18

Data table after enrichment

Campaign

Ad Group

Clicks

Campaign and Ad Group

Brand

media

7

Brand_media

Brand

ecommerce

3

Brand_ecommerce

Dashboard

media|social

18

Dashboard_media|social