12-21-2022 02:55 AM
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.
Solved! Go to Solution.
12-21-2022 03:11 AM
12-21-2022 03:11 AM
12-21-2022 03:16 AM
@pmancevski Thank you for the quick response. It helped.
12-21-2022 04:37 AM
@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
12-21-2022 06:19 AM
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.