Sum strings within an array/collection using a formula (not iterator)

Hi everyone,

After a JSON parse, I am left with a bundle which has an array called inventory. In this example, there are two collections in this array. Within each collection, there is a key called inventory_price.

So for this one bundle, there are two inventory items, each of which has a price.

I believe the issue is that the value is a string, not a number.

I know I can use an iterator to loop through the inventory array and sum these values using different methods (set variable or number aggregator).

I’d like to do this in as few steps as possible and want to know if I can do it with a formula. If I try to use the map function, it does return an array with those two prices. However, if I try to use a sum(map( then I get an error.

Can I do this with a formula?

Welcome to the Make community!

You can use the built-in functions map and sum.

For more information on the map function, see

Links

Here are some useful links and guides to help you get started and learn more on how to use the Make platform, apps, and app modules —

General

Help Center Basics

Articles & Videos

samliewrequest private consultation

2 Likes

Would that work no matter how many bundles I have? I understand if I always want to sum the first 2, I can make a formula using map and choosing the first two bundles. But how would I make that flexible regardless of the number of bundles?

If you have multiple bundles and you want to combine them, you should use an aggregator.

Every result (item/record) from a search/match module will output a bundle. To “combine” them into a single structure, you’ll need to use an aggregator of some sort.

Aggregators are modules that accumulate multiple bundles into one single bundle. An example of a commonly-used aggregator module is the Array aggregator module. The next popular aggregator is the Text Aggregator which is very flexible and has applies to many use-cases.

There are other types of aggregator modules, click the below links to find out more:

If you need further assistance, please provide the following:

Please provide the output bundles of the relevant modules by running the scenario (or get from the scenario History tab), then click the white speech bubble on the top-right of each module and select “Download input/output bundles”.
Screenshot_2023-10-06_141025

A.

Save each bundle contents in your text editor as a bundle.txt file, and upload it here into this discussion thread.

Uploading them here will look like this:

module-1-output-bundle.txt (12.3 KB)

B.

If you are unable to upload files on this forum, alternatively you can paste the formatted bundles in this manner:

  • Either add three backticks ``` before and after the code, like this:

    ```
    input/output bundle content goes here
    ```

  • Or use the format code button in the editor:
    Screenshot_2023-10-02_191027

Providing the input/output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.

This will allow others to better assist you. Thanks!

samliewrequest private consultation

1 Like