How do I format multiple arrays into rows in excel?

:bullseye: What is your goal?

I’m pulling fiscal data from an API using the Make Code module. My Python returns a proper 2-D array, where each internal array represents one spreadsheet row, for example:

values = [
[“CAT - INCOME STATEMENT (STANDARDIZED, ANNUAL)”, “”, “”, …],
[“Line Item”, “FY2024”, “FY2023”, “FY2022”, …],
[“Total Revenues”, 64809000000, 67060000000, …],
[“Cost of Sales”, 40199000000, 42767000000, …],

]

I am trying to bulk insert these rows into Google Sheets so each inner array becomes its own row into a complete table.

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

When I send this values array to Google Sheets using Make, Sheets inserts EVERYTHING into one single row (A1:ZZ1) and not delimited within each cell…

Instead of:
Row 1 = section title
Row 2 = header row , data…
Row 3 = first data row , data…
etc…

I honestly have no idea what the issue is, it looks like the data is formatted correctly, but i guess not. I am attaching screenshots of the Code Module, Bulk Add Row Module, and a picture of the sheet for reference.

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

@mfairfld Right now, you have the Map option “on” or “green” so it’ll insert everything from (59. Result) in a single row or cell.

I think what you should do is to turn the Map option “off” or “grayed” for Rows. This way you can map out each array in (59. Result) to its own specific rows in Google Sheet.

I hope that helps you!

Hi @Karmic, thank you for taking a look. I think this is progress, however, when I uncheck the map button, I am not able to select each array under (59. Result), it only shows the first one. I am guessing that it is because all 93 arrays are under 1 bundle? I am not completely sure. I will attach a photo.

Just delete any Row sub-blocks (click the x icon). Click the Rows field itself and map (59. Result).

As far as I can see your code outputs a bundle with a 2-D array ([[A1,B1,…],[A2,B2,…],…]) so mapping the (59. Result) is enough to tell Google Sheets to input your array into its own row and each item into its own column.

Let me know how it goes!

Welcome to the Make community!

From your screenshot / output bundle, it appears that you have an array of items. What do you do when you have an array?

“Looping” Through Array Items

When you see an array in a module’s output, think of using an Iterator module. This allows you to individually access and process each item in the array.

In this example, this variable is an array of items (collections). You’ll want to map this variable in an Iterator module.

Question: Have you tried mapping your array variable into an Iterator module, ran the scenario once, and view the output?

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 each subsequent modules once per bundle, which is not optimal in most cases:

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?

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 items/collections.

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

As you can see from the above example, the “Map” toggle on complex 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 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?

Example

Here is an example of how your scenario could look like:

This is just an example. Your solution may or may not look like this depending on requirements and actual data.

For more information, see “Mapping with arrays” in the Help Centre. You should also do the Make Academy, which also covers the use of Iterators & Aggregators.

Hope this helps! If you are still having trouble, please provide more details.

@samliew
P.S.: investing some effort into the tutorials in the Make Academy will save you lots of time and frustration using Make!