Adds a new field by using a Python expression. The position of the new field within the table is set using the Field Index. A Field Index of 0 corresponds to the first position, 1 corresponds to the second position, and so on. To add the field to the last position, change the index to -1.
Example 1

dim_A | dim_B | metric_1 |
AAA | DDD | 111 |
BBB | EEE | 222 |
CCC | FFF | 333 |
dim_A | dim_B | metric_1 | newfieldname |
AAA | DDD | 111 | AAA_DDD |
BBB | EEE | 222 | BBB_EEE |
CCC | FFF | 333 | CCC_FFF |
Example 2
Numeric calculations require integers and floats as inputs, strings cannot be used during numerical calculations. For example, the value of "222" may be stored as a string when it needs to be an integer for the numeric calculations. To complete the example below, you first need to run a convertnumbers transformation. This will convert all string fields into integers.
dim_A | metric_1 | metric_2 |
AAA | 111 | 444 |
BBB | 222 | 555 |
CCC | 333 | 666 |
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",
{
"index": -1,
"subtable": null,
"field": "newfieldname",
"expression": "{dim_A} + '_' + {dim_B}",
"_comment": null
}
]
Example 2
[
"addfieldx",
{
"index": -1,
"subtable": null,
"field": "division_field",
"expression": "({metric_1} + {metric_2}) / 100",
"_comment": null
}
]
param str subtable: Name a subtable in which output will be stored (will create subtable where necessary). If you do not want to create a subtable, enter "null".
param int index: Position of new field (first position = 0, last position = -1).
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.