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)