SUM values from different Operations

:bullseye: What is your goal?

Hi,
I am building a nutrition calculator. ingredients and their amount in g are getting sent from adalo. after the scenario is supposed to search each ingredient in the USDA database, filter the relevant nutrients, calculate the correct amount and then sum the outputs for each nutrient. I have it worked out until now I have to sum.

I have all values but I have them in different operations. How can I bring these together? Please help me I am going crazy by now…

:thinking: What is the problem & what have you tried?

I’ve tried aggregators, numeric aggregators, data storages…

:camera_with_flash: Screenshots (scenario flow, module settings, errors)

1 Like

Hey Carlotta,

you want a Numeric Aggregator to sum the results. Or a generic aggregator and then sum the array afterwards.

Hi @CarlottaHelena ,

To calculate the sum of values across multiple operations, you need to use a Numeric Aggregator module. This module aggregates numeric values from multiple bundles into a single output. Please refer to the screenshot for guidance on how the Numeric Aggregator processes multiple operations.


If the data is not coming as multiple operations (i.e., a single bundle), you can directly use the sum() function available in Make.com to calculate the total.

Additionally, we noticed a Set multiple variables module placed after the Iterator. If this module has a specific purpose in your scenario or is required for further processing, please let us know so we can better understand the use case and assist you accordingly.

Best regards,
Msquare Automation
Platinum Partner of Make
@Msquare_Automation

thank you so much for your response!


the set multiple variables module is calculating “scaledAmount”: the amount of the nutrient per the amount it is in the dish (200 g of chicken breast - 20g protein per 100g - 40g) and saves it.
For every ingredient I get max 5 (depending on database extent) values for each nutrient.

My goal is to sum the scaledAmounts of each nutrientNumber:
In the screenshot I uploaded e.g. I have 2 bundles with the nutrientNumber 203 and different scaledAmounts which I want to sum.

I’ve tried to get these bundles into an array, but since they’re multiple operations make creates an array per operation…

In your example you have only one operation as well!

1 Like

Hey Stoyan,
unfortunately that works only with multiple bundles, not with multiple operations I think?

Hi @CarlottaHelena ,

You can calculate the sum using the Numeric Aggregator, as shown in the screenshot. Please refer to it for the exact configuration.



In the Numeric Aggregator, make sure to set the Group by field to nutrientNumber, since this is the common value in your case and ensures that all entries with the same nutrient number are aggregated together.

In the Value field, apply the following calculation:

{{51.amount * 51.grams / 100}}

In our setup, we performed this operation by replacing the “Set multiple variables” module.
If this module has a specific purpose in your scenario or is required for further processing, please let us know so we can better understand the use case and assist you accordingly.

Best regards,
Msquare Automation
Platinum Partner of Make
@Msquare_Automation

unfortunately this only works with 1 operation. I am again getting one operation for each ingredient, the sum does not work.

1 Like

You are aggregating the wrong iterator. That one is not producing multiple bundles, hence it is not giving you a sum.

Hi @CarlottaHelena ,

You’ve currently selected Iterator [23] as the source module, which processes one operation per ingredient, causing the total sum to be calculated incorrectly.

To fix this, please select Iterator [16] as the source module in the Numeric Aggregator. This will aggregate the data correctly and resolve the issue with the sum calculation.

Best regards,
Msquare Automation
Platinum Partner of Make
@Msquare_Automation

Welcome to the Make community!

Combining Bundles Using Aggregators

Every result/item from some module types (like Trigger / Iterator / List / Search / Match modules) can potentially and likely output more than one bundle. These multiple bundles will individually run subsequent modules once per bundle, which is not optimal in most cases:

  • one operation per bundle per module, which could lead to…
  • use of multiple credits per bundle per module (some modules use more than one credit)
View example screenshots

Aggregator Example

The “Search Rows” module runs one time, returning 999 results (999 bundles).

  • Without Aggregator: the tools module run 999 times (999 operations)


    (and if there are more modules, they run 999 times each)

  • With Aggregator: the tools module only runs 1 time (1 operation)

:warning: Warning: :police_car_light:
This can easily use your entire quota of credits if you are not careful or fail to understand this concept.

To “combine” multiple bundles into a single variable, so that you can process all of the items in a single operation, you’ll need to use an aggregator. Aggregators is a type of module that accumulates bundles and outputs one bundle (unless you are using “Group By”). An example of a commonly-used aggregator module is the Array aggregator module.

You can find out more about some other aggregator modules here:

Question: Which is the best aggregator do you think you’ll need for your use-case?

Setting the Correct Aggregator Source

You need to set the “Source Module” field of the aggregator to where the bundles are coming from. This is usually an iterator module, but can also be a search/list/repeater module, or even the trigger module!

Mapping a Complex (Collection) Structure Into an Array Field

The Array Aggregator module is very powerful because it allows you to build a new complex array of collections that matches a later module’s array field to map multiple items (collections) to it. Such fields initially may allow you to manually add individual items, but toggle the “Map” switch on, and you can map an array variable (from an Array Aggregator) containing multiple collections.

Simply select the respective “Target structure type” in an Array Aggregator module.

As you can see from the example above, the “Map” toggle on complex array fields are used when you have an array variable (like from an array aggregator).

:clipboard: Note: :light_bulb:
Other combinations of modules may also allow you to generate an array that matches a future module field’s array structure, like “Aggregate to JSON + Parse JSON”, or “Create JSON + Parse JSON”, but this is an advanced topic.

Question: Are you mapping your array into a field that accepts more than one item/collection?

For more information, see “Mapping with arrays” in the Help Centre. I also suggest going through the Make Academy, which also covers the use of Iterators & Aggregators.

Links & Guides

Here are some useful links and guides you can use to learn more on how to use the Make platform, apps, and app modules. I’d also recommend going through the Make Academy if you haven’t yet!

Learn Make

How-Tos

— @samliew