Sum of value of all items in array

Greetings,

I have an array of products like below where the same item may appear more than once with a different qty:

{
  "items" : [
    {
      "sku": "123",
      "qty": 10
    },
    {
      "sku": "123",
      "qty": 5
    },
    {
      "sku": "XYZ",
      "qty": 3
    }
  ]
}

I need to calculate the total qty of each sku.

An example of what I’m trying to get to would be:

{
  "items" : [
    {
      "sku": "123",
      "qty": 15
    },
    {
      "sku": "XYZ",
      "qty": 3
    }
  ]
}

I think I need to use something with Group records, but I’m not sure how to calculate the total after that.

Suggestions?

Thanks!

Yes, that’s right, you can use Group Records, but of course you need to add other transformers to achieve this. You can see an example in the following file:

sample-forum-674_transformer.ndjson (1.1 KB)

To be able to try it, you need to import it into your Alumio. For the steps, you can see here.

1 Like

Thank you! This was just what I needed to get me on the right path to the solution I needed!

1 Like