Add a column that sums up another column row by row. Typically, it is best practice to aggregate/sort data accordingly before performing this operation.
Example
Example Input
date | key_1 | key_2 | imp |
2018-01-01 | a | b | 1 |
2018-01-01 | a | c | 1 |
2018-01-01 | b | b | 1 |
2018-01-02 | a | b | 1 |
2018-01-02 | a | c | 1 |
2018-01-02 | b | b | 3 |
2018-01-03 | a | b | 1 |
2018-01-03 | a | c | 2 |
Example Output
key_1 | key_2 | date | imp | imp_increment |
a | b | 2018-01-01 | 1 | 1 |
a | b | 2018-01-02 | 1 | 2 |
a | b | 2018-01-03 | 1 | 3 |
a | c | 2018-01-01 | 1 | 1 |
a | c | 2018-01-02 | 1 | 2 |
a | c | 2018-01-03 | 2 | 4 |
b | b | 2018-01-01 | 1 | 1 |
b | b | 2018-01-02 | 3 | 4 |
I Ain't Afraid of No Code!
[
[
"sumup",
{
"discriminators": [
"key_1",
"key_2"
],
"subtable": null,
"fieldname": "imp_increment",
"sourcefield": "imp",
"_comment": null
}
]
]
param list discriminators: Define a key consisting of multiple fields as discriminator to reset the sum to zero whenever the key changes.
param str subtable: Name a subtable in which output will be stored (will create subtable where necessary).
param str fieldname: Name of Outputfield holding the incremental sums.
param str sourcefield: Column to be summed up. Must be of type "number".
param str comment: A comment that will appear in the Transformation UI.
Comments
0 comments
Article is closed for comments.