Sum in a loop

Hi,
I have an default value for field $sum=390 and 10 input records(count may increase/decrease).
Requirement :Each row should get $sum=$sum+10. if 1st row having sum=400, 2nd sum=410…
Please suggest.

Hi @nirupama,

You can use “Mapper” snap, with following settings:

Thanks,
Pero M.

1 Like

@pmancevski Thank you for the quick response. It helped.

@pmancevski How to apply the same logic on group by values. Sample data is attached below. Sum should be incremented by 10 for each row.
[
{
“groupBy”: {
“number”: “1115122”
},
“group”: [
{
“name”: “TD”,
“number”: “1115122”,
“sum”: “390”
},
{
“name”: “TD”,
“number”: “1115122”,
“sum”: “390”
}
]
},
{
“groupBy”: {
“number”: “1115982”
},
“group”: [
{
“name”: “TD”,
“number”: “1115982”,
“sum”: “390”
}
]
},
{
“groupBy”: {
“number”: “1115962”
},
“group”: [
{
“name”: “TD”,
“number”: “1115962”,
“sum”: “390”
}
]
}
]

required output:
1st group : sum=400, 410
2nd group : sum=400
3rd group : sum=400

Hi,

Probably there is simpler solution, but at the moment i can think only this:

Replace previous expression with this:
$group.map((value, index) => value.extend({“sum” : parseInt(value.sum) + ((index + 1) * 10)}))

We are extending the object with same field, because previously we had that field name, it will be only overwritten.

Thanks,
Pero M.

@pmancevski $group.map((value, index) => value.extend({‘sum’ : parseInt(value.sum) + ((index + 1) * 10)})) - This expression solved my query.

Thank you!