# Aggregate data from multiple operations

**URL:** <https://community.make.com/t/aggregate-data-from-multiple-operations/24920>\
**Category:** Questions\
**Tags:** aggregators, operation\
**Created:** [January 21, 2024, 2:53pm UTC](https://community.make.com/t/aggregate-data-from-multiple-operations/24920 "2024-01-21T14:53:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eli\_Rozen](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/eli_rozen/32/24088_2.png) [@Eli\_Rozen](https://community.make.com/u/Eli_Rozen)\
**Post date:** [January 21, 2024, 2:53pm UTC](https://community.make.com/t/aggregate-data-from-multiple-operations/24920/1 "2024-01-21T14:53:05Z")

</div>

I am trying to aggregate data that is “deeply” nested in Collections, the total number of which is variable.

In this data an array of _Customers_ collections each includes an array of _“Custom Field Values”_ collections, in which I am trying to `sum()` up the _“Display\_Value”_ in the _“PAX 12pk”_ collections. These are text format so I do have to `parseNumber()` on it.

 ![Screenshot 2024-01-20 125907](https://europe1.discourse-cdn.com/flex013/uploads/make/original/3X/4/8/48ee180dc726471f293d56b818ff56d293354b28.png)

So far I have a **Repeater** based on `length(Customers[])` which feeds into a **Set Multiple Variables** that Maps the _“Customers[].Custom\_Field\_Values[].Name”_ and _“Customers[].Custom\_Field\_Values[].Display\_Value”_ into respective.  
This feeds into an **Iterator** that breaks down the _“Customers[].Custom\_Field\_Values[].Name”_ array from the **Set Multiple Variables** , goes through a **Router** and filters on the _“Customers[].Custom\_Field\_Values[].Name”_ for `contains(PAX)`.  
I use a second **Set Multiple Variables** to `parseNumber(Customers[].Custom_Field_Values[Iterator.Bundle.Bundle_Order_Positions].Display_Value)`.  
**Note:** Though the PAX collection is currently always in the first position, the reason I’m doing it this way is in case the _“Custom\_Field\_Values”_ order/variables ever change in the future.  
In the example shown 2 Operations are generated. How can I sum up the _“PAX 12pk”_ values from the 2 Operations back into a single variable/operation?  
I tested an **Aggergator** , but that only works within operations, not over multiple operations which I’m trying to solve for.  
Am I even on the right track for the solution?

 ![Screenshot 2024-01-20 124853](https://europe1.discourse-cdn.com/flex013/uploads/make/original/3X/b/1/b15b0b7c5d0e2e43435910b8df2671981cdf2b9b.png)

---

<div class="post-metadata">

**Author:** ![Eli\_Rozen](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/eli_rozen/32/24088_2.png) [@Eli\_Rozen](https://community.make.com/u/Eli_Rozen)\
**Post date:** [January 21, 2024, 4:14pm UTC](https://community.make.com/t/aggregate-data-from-multiple-operations/24920/2 "2024-01-21T16:14:01Z")

</div>

A solution which is working:  
Since I’m saving the data in **Data Store** I can use a variable in the struct that is preset to 0.  
By using **Get Record** I can then sum up the variable in the **Update Record**.  
In this example the record variable is called _“PAX”_, thus in the **Update Record** I run `Get_Record.PAX + parseNumber(Customers[].Custom_Field_Values[Iterator.Bundle.Bundle_Position].Display_Value)`

 ![Screenshot 2024-01-21 100643](https://europe1.discourse-cdn.com/flex013/uploads/make/original/3X/e/c/eccfd8150caa5d445324126bf50a230051cbeec8.png)  
This also saves on a module and the associated operations.

Let me know if you have another solution. I would be interested what else is possible if, for example, I wasn’t using a Data Store.

---

<div class="post-metadata">

**Author:** ![Lauren\_Moineau](https://avatars.discourse-cdn.com/v4/letter/l/3ab097/32.png) [@Lauren\_Moineau](https://community.make.com/u/Lauren_Moineau)\
**Post date:** [January 21, 2024, 4:15pm UTC](https://community.make.com/t/aggregate-data-from-multiple-operations/24920/3 "2024-01-21T16:15:55Z")

</div>

Hi @Eli_Rozen I would do it in 3 modules:

 ![Screenshot 2024-01-21 170842](https://europe1.discourse-cdn.com/flex013/uploads/make/original/3X/e/e/eedb7631f2ec9a13072e3aa17ee31154a391b85b.png)

- an iterator to iterate through your main array `Customers[]`
- A Set Variable module to first map all the values of the `Pax 12pk` for each item of that main array, using a filter, then sum them up:  
`{{sum(map(Customers[].Custom_Field_Values[]; "display_value"; "name"; "PAX 12pk"))}}`  
(Make sure to pass the raw values for `diplay_value` and` name` )
- a Number Aggregator module to sum all those previous sums:  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/make/original/3X/4/e/4edcaef63a34e6a28d98f7c2eec75c6b2220269d.png)  
Hope that helps 🙂

---

<div class="post-metadata">

**Author:** ![Eli\_Rozen](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/eli_rozen/32/24088_2.png) [@Eli\_Rozen](https://community.make.com/u/Eli_Rozen)\
**Post date:** [January 21, 2024, 5:26pm UTC](https://community.make.com/t/aggregate-data-from-multiple-operations/24920/4 "2024-01-21T17:26:30Z")

</div>

@Lauren_Moineau thank you but I’m a little confused about your approach.

In my example, I need to sum up `Customers[1].Custom_Field_Values[x].Display_Value + Customers[2].Custom_Field_Values[x].Display_Value +... Customers[n].Custom_Field_Values[x].Display_Value`

I’m not seeing how I iterate through each _“Customers[1 to n]”_ in the summation/aggregation step, or basically how I’m creating the array of `<Customers[1].Custom_Field_Values[x].Display_Value, Customers[2].Custom_Field_Values[x].Display_Value,... Customers[n].Custom_Field_Values[x].Display_Value>`

---

<div class="post-metadata">

**Author:** ![Eli\_Rozen](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/eli_rozen/32/24088_2.png) [@Eli\_Rozen](https://community.make.com/u/Eli_Rozen)\
**Post date:** [January 21, 2024, 5:29pm UTC](https://community.make.com/t/aggregate-data-from-multiple-operations/24920/5 "2024-01-21T17:29:01Z")

</div>

Simple update, I moved the **Get Record** before the **Router** so that the record is available in all the branches in case I need to aggregate other variables.

 ![Screenshot 2024-01-21 102129](https://europe1.discourse-cdn.com/flex013/uploads/make/original/3X/b/6/b615183d1262aa3e80c4ace8f1c13f535a376aa5.png)

**UPDATE:** scratch that approach, since I have 8x Custom Field Values in each Customers, the **Get Record** runs 8x # of Customers, so 8 operation at minimum and 16 operations in my example (didn’t see it initially because I was filtering out everything but PAX before) 😵‍💫 😅

Where to put the **Get Record** will depend on the most efficient # of operations you get each run based on average possible loops, bundles generated in earlier steps, and filtering of the links.

---

<div class="post-metadata">

**Author:** ![Lauren\_Moineau](https://avatars.discourse-cdn.com/v4/letter/l/3ab097/32.png) [@Lauren\_Moineau](https://community.make.com/u/Lauren_Moineau)\
**Post date:** [January 21, 2024, 6:15pm UTC](https://community.make.com/t/aggregate-data-from-multiple-operations/24920/6 "2024-01-21T18:15:59Z")

</div>

@Eli_Rozen  
1- **Iterator**  
We iterate through your `Customers[]` array, creating a separate bundle for each customer: one bundle for customers[1], then one for Customers[2] and so on.

2- **Set Variable module**  
At each iteration, for each bundle of data, we go into that `Custom Field Values` array.  
I assumed you could have several items named `PAX 12pk` in that array.  
We create a sum of the values of all the `PAX 12 pk` for that given customer (thanks to the map() and sum() functions).  
We are returning the sum of `Customers[n].Custom_Field_Values[x].Display_Value` you need (if I understand correctly) for a given customer.

`(map(Customers[].Custom_Field_Values[]; "display_value"; "name"; "PAX 12pk")` says  
“For this customer, take the nested array `Customers[].Custom_Field_Values[]` and return an array of `display_value` where the name is `PAX 12k`”  
(we do this at each iteration, for each customer)

Then `sum()` returns the sum of the values of that array.

If you only have one item named `PAX 12pk` in the `Custom Field Values` array for each customer, you could replace `sum()` with `first()`, which will return the first and unique value of the map() array. The function would then be:  
`first((map(Customers[].Custom_Field_Values[]; "display_value"; "name"; "PAX 12pk"))`

3- **Aggregator**  
We take the value generated for each customer/bundle and sums them all.

Hope that’s clearer. Have you tried it and does it work for you?

---

<div class="post-metadata">

**Author:** ![Eli\_Rozen](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/eli_rozen/32/24088_2.png) [@Eli\_Rozen](https://community.make.com/u/Eli_Rozen)\
**Post date:** [January 21, 2024, 7:30pm UTC](https://community.make.com/t/aggregate-data-from-multiple-operations/24920/7 "2024-01-21T19:30:17Z")

</div>

@Lauren_Moineau  
I believe I understand what you mean now, but correct me if I’m still missing it based on my response here:

Unfortunately in my case, there is only 1x `PAX 12pk` type `Custom Field Values` container inside each `Customers` container, and I need to aggregate the `PAX 12pk` values ACROSS `Customers[]`, not WITHIN

See the structure in the picture, `PAX 12pk` is only `Custom_Field_Values[1]` in each `Customers[]`, `Custom_Field_Values[2-8]` are something completely different

 ![Screenshot 2024-01-21 132425](https://europe1.discourse-cdn.com/flex013/uploads/make/original/3X/d/2/d2b6ffc9462bec038412ff2703dcbd7dd3cf9312.png)

Thank you for the discussion.

---

<div class="post-metadata">

**Author:** ![Lauren\_Moineau](https://avatars.discourse-cdn.com/v4/letter/l/3ab097/32.png) [@Lauren\_Moineau](https://community.make.com/u/Lauren_Moineau)\
**Post date:** [January 21, 2024, 8:38pm UTC](https://community.make.com/t/aggregate-data-from-multiple-operations/24920/8 "2024-01-21T20:38:59Z")

</div>

@Eli_Rozen No problem 🙂  
Based on your screenshot, the Set Variable in my scenario would return `13` for the first bundle (customer 1) and` 6` for the second bundle (customer 2).  
If you don’t have more customers, the Numeric Aggregator will then return `19`.

Now, correct me if I’m wrong, you’re saying that `PAX 12pk` will always be in the 1st item of the Custom Field Value.  
If you’re 100% certain that it will _always_ be the case, then you can keep the same scenario and just change the function in the second module.

- Iterator (passing in your main Customers array)
- Set Variable (getting the value of display\_value for each customer) with the following function:  
`parseNumber(get(Customer Field Values[1].display_value; 1))`  
(you don’t really need the `parseNumber` here as Make will transform the text into number when you create the sum later, but it doesn’t cost anything more 🙂 )
- Numeric aggregator, a sum() of the previous variables.

Now I’m thinking, do you need to have an intermediary step, i.e an array of all the display\_values? Or is the final sum okay (as here)?

---

<div class="post-metadata">

**Author:** ![Eli\_Rozen](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/eli_rozen/32/24088_2.png) [@Eli\_Rozen](https://community.make.com/u/Eli_Rozen)\
**Post date:** [January 22, 2024, 4:18pm UTC](https://community.make.com/t/aggregate-data-from-multiple-operations/24920/9 "2024-01-22T16:18:30Z")

</div>

hey @Lauren_Moineau,  
In answer to your question, it’s not 100% the `PAX` will remain in the first position. I Iterate the `Custom Field Values` by `"name"`, to obtain its position.

But I’m still missing a couple of things:  
1 - why am I iterating the `Customers[]` array specifically? I’m not seeing what data I’m using from that module  
Can’t I just reference `Customers[].Custom_Field_Values[]....` as needed, and I know the number of bundles based on `length(Customers[])`  
2 - I still haven’t gotten your approach working properly, but won’t `Set Variables` break the 2 (or more) bundles into separate operations, not just bundles. This was my initial issue of how to bring values from 2 different operations.

On a side note, that `PAX` variable will be named one several different ways; `PAX 12pk`, `PAX 10pk`, or `PAX ski`, but it will always contain “PAX” in the name.  
This is why I’m mapping the `Custom_Field_Values[]` name, then iterating to filter the bundle containing “PAX,” and using that bundle position in the next module. I wonder how this changes your solution?

---

<div class="post-metadata">

**Author:** ![Make\_Bot](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/make_bot/32/14661_2.png) [@Make\_Bot](https://community.make.com/u/Make_Bot)\
**Post date:** [February 4, 2024, 4:28pm UTC](https://community.make.com/t/aggregate-data-from-multiple-operations/24920/10 "2024-02-04T16:28:22Z")

</div>


