Question

Sum of amounts in Products Array

  • 22 September 2020
  • 1 reply
  • 33 views

Hi

I was trying to create a report with the sum of all revenue associated to each product (array) but couldn’t get it to work. 

For example, on an “Order Completed” event, I’d have some products

products: [
{
name: "1",
amount: 30,
},
{
name: "2",
amount: 20,
},
{
name: "3",
amount: 15,
},

And want to obtain a “sum” of all amounts for product 1, then 2, then 3.

This would also be useful for attribution models. For example:

event: "Attribution Calculated",
properties: {
channels: [
{
source: "facebook",
medium: "paid",
content: "form1",
revenue: 30,
},
{
source: "google",
medium: "paid",
content: "campaign1",
revenue: 20,
},
{
source: "facebook",
medium: "organic",
content: "campaign1",
revenue: 15,
},
],
},

 

“Total” works fine (below):

 

But “Sum” of “channels_revenues” results in a count (0) of events:

 

 

Can you please advise?


1 reply

Userlevel 5
Badge +3

@humberto —

What happens if you breakdown the report by property = “channels_revenue” and you do not sum it? Do you see the property values?

 

It looks like you may be recording these values as a string, which is why when they “sum” it shows up as zero. Instead, you may need to typecast the property first in order to sum the values. 

Reply