Solved
Forum Discussion
Hi @bojanvelevski, Thanks for the response.
This Aggregation just gives the sum of all the values that is 60., but we need the cumulative sum in every record as shown in the example output.
sum = sum in the previous record + key2 in the current record.
bojanvelevski
4 years agoValued Contributor
Here’s a corrected version of the expression:
$array.map((x,index)=> index==0 ? x.extend({sum:x.key2}) : x.extend({sum:$array.slice(0,index+1).reduce((acc,curr)=> acc+curr.key2,0)}))
Let me know if this works for you, and I will explain in details on how the expression works.
This is perfect @bojanvelevski
I was trying with index, map and your expression is better than mine. 🙂Would you mind explaining the reduce function used here?