Adds a field using an expression. The position of the new field within the table is set by the Field Index, using the appropriate integer value (0 onward, moving left to right). If Field Index is left blank, the new field will automatically be added as a final column to the existing dataset.
Example 1

Example Input 1
dim_A | dim_B | metric_1 |
AAA | DDD | 111 |
BBB | EEE | 222 |
CCC | FFF | 333 |
Example Output 1
dim_A | dim_B | New_Field | metric_1 |
AAA | DDD | AAA_DDD | 111 |
BBB | EEE | BBB_EEE | 222 |
CCC | FFF | CCC_FFF | 333 |
Example 2
In order to perform numeric calculations as per the below example, you first need to run a convertnumbers transformation, otherwise the fields will be considered strings rather than integers.

Example Input 2
dim_A | metric_1 | metric_2 |
AAA | 111 | 444 |
BBB | 222 | 555 |
CCC | 333 | 666 |
Example Output 2
dim_A | metric_1 | metric_2 | division_field |
AAA | 111 | 444 | 5.55 |
BBB | 222 | 555 | 7.77 |
CCC | 333 | 666 | 9.99 |
I Ain't Afraid of No Code!
Example 1
[
"addfieldx",
{
"field": "New_Field",
"expression": "{dim_A} + '_' + {dim_B}",
"subtable": null,
"index": null,
"_comment": null
}
]
Example 2
[
"addfieldx",
{
"field": "division_field",
"expression": "({metric_1} + {metric_2}) / 100",
"subtable": null,
"index": null,
"_comment": null
}
]
param str subtable: Name a subtable in which output will be stored (will create subtable where necessary).
param int index: Position of new field (first position = 0).
param str field: Name of the field to be added.
param str expression: Expression for new field.
param str comment: A comment that will appear in the Transformation UI.
Comments
0 comments
Article is closed for comments.