cancel
Showing results for 
Search instead for 
Did you mean: 

Sum in a loop

nirupama
New Contributor II

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.

1 ACCEPTED SOLUTION

pmancevski
New Contributor III

Hi @nirupama,

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

image

Thanks,
Pero M.

View solution in original post

5 REPLIES 5

pmancevski
New Contributor III

Hi @nirupama,

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

image

Thanks,
Pero M.

nirupama
New Contributor II

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

nirupama
New Contributor II

@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

pmancevski
New Contributor III

Hi,

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

image

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.