Failed to map 'value': Function 'average' finished with error! Function 'map' finished with error! '{empty}' is not a valid key

Hi everyone! :waving_hand:

I’m working with an array of 12 months data (each item has a close value and a datetime like this):

This array is generated from an Array Aggregator, and I want to calculate the average close value of the latest 10 months using a Set variable module.

Here’s the expression I tried:
{{average(map(slice(8.array; 0; 10); get(8.array; “close”)))}}

But this gives me an error:

Function 'map' finished with error! '{empty}' is not a valid key.
or sometimes: Function 'number' not found!

I also tried different approaches with current, number(), etc., but it seems not all functions are available in Set variable.

Has anyone managed to process a sub-array (first 10 values) and calculate a numeric average from a key like "close"?

Welcome to the Make community!

You should map first before slicing. Also, you don’t need to use get, because you are not getting a single item. Try this:

{{ average(slice(map(8.array; "close"); 0; 10)) }}

(copy-paste the above into the field, or type it exactly as shown)

Hope this helps! Let me know if there are any further questions or issues.

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