Flatten an array into a combined results and key string

Heya Makers,

A numeric aggregator sums up and groups result by a value.

An an array aggregator then turns the bundles into an array.

[
    {
        "array": [
            {
                "result": 6,
                "__IMTKEY__": "Ask"
            },
            {
                "result": 2,
                "__IMTKEY__": "Treva "
            },
            {
                "result": 2,
                "__IMTKEY__": "Petit Elita "
            }
        ],
        "__IMTAGGLENGTH__": 3
    }
]

Would it be possible flatten the array into an output as below without using additional iterators/aggregators and only inline functions?

The desired result

6 Ask
2 Treva
2 Petit Elita

Hi @Zbulo , hope you are doing well.

I tried this scenario with Iterator and Text Aggregator first, got your desired result

I also get the output with a function called {{toCollection(17.array; “result”; “IMTKEY”)}}


but in this case I don’t know why do I get only 2 items instead of 3. Can you please try from your end. It should produce all 3 items.

Note: There is a function call flatten() as well I tried that but did not get proper result in this situation.

1 Like

You’ll definitely need an Iterator + Text Aggregator.

This is because it is not a primitive array, but an array of collections.

samliew – request private consultation

Join the Make Fans Discord server to chat with other makers!

2 Likes

If you provide the output of the Numeric Aggregator I might be able to make a solution that uses 2 less operations.

When asking for help on this forum, it is important not to omit the beginning part of your scenario.

samliew – request private consultation

Join the Make Fans Discord server to chat with other makers!

You’re right, thanks for the best practive suggestion.

Here’s an overview of the simplified scenario

  1. Search records
  2. Filter and sum total
  3. Search records once more
  4. Sum and group by
  5. Aggregate bundles into an array.
  6. Convert array of collections into string.

Output

  1. The output of the numeric aggregator is what I posted earlier:
[
    {
        "result": 6,
        "__IMTKEY__": "Ask"
    },
    {
        "result": 2,
        "__IMTKEY__": "Treva "
    },
    {
        "result": 2,
        "__IMTKEY__": "Petit Elita "
    }
]
  1. The aggregator turns this into one bundle
[
    {
        "array": [
            {
                "result": 6,
                "__IMTKEY__": "Ask"
            },
            {
                "result": 2,
                "__IMTKEY__": "Treva "
            },
            {
                "result": 2,
                "__IMTKEY__": "Petit Elita "
            }
        ],
        "__IMTAGGLENGTH__": 3
    }
]

I hope this makes sense. Thanks!

After the Numeric Aggregator you can immediately aggregate to text.

Output

Screenshot_2024-06-29_210647

samliew – request private consultation

Join the Make Fans Discord server to chat with other makers!

1 Like