cancel
Showing results for 
Search instead for 
Did you mean: 

Group and Sum in Expression Language

wcl3y2
New Contributor III

I am trying to group and sum an amount by two properties with the expression language with no luck. I tried using the reduce function, but it’s not working like it does in traditional javascript. Is there any way to get this to work? Here is my input document:

[
{
“ro”: [
{
“prod”: “product1”,
“div”: “division1”,
“amount”: 178.25
},
{
“prod”: “product1”,
“div”: “division2”,
“amount”: 758.65
},
{
“prod”: “product1”,
“div”: “division2”,
“amount”: 10000.79
},
{
“prod”: “product2”,
“div”: “division2”,
“amount”: 5678.10
}
]
}
]

Here is my expected output:

[
{
“ro”: [
{
“prod”: “product1”,
“div”: “division1”,
“amount”: 178.25
},
{
“prod”: “product1”,
“div”: “division2”,
“amount”: 10759.44
},
{
“prod”: “product2”,
“div”: “division2”,
“amount”: 5678.10
}
]
}
]

3 REPLIES 3

tstack
Former Employee

What was the expression you tried that didn’t work?

wcl3y2
New Contributor III

I was able to use the reduce function to handle this. I made a simple mistake in one of my attempts and abandoned it too quickly.

Ajay_Chawda
Contributor

Hi @wcl3y2
i tried to implement using aggregate snap.
testW3C_2020_04_26 (1).slp (6.0 KB)