Ungroup Function

Is there a formula function that is the opposite to ''Group" i.e. ungroup?

Hi, there is no specific UNGROUP formula. You could try using MAP to transform the data back into its original format:

1 Like

Hi Mari,

Thanks for your reply. I’m not sure how we would use MAP to acheive what we need.

Lets say our API gives us a list of products grouped by category eg:

[
    {
        "category": "Utility",
        "products": [
            {
                "name": "Duct tape",
            },
            {
                "name": "Glue",
            }
        ]
    },
    {
        "category": "Tools",
        "products": [
            {
                "name": "Swiss army knife",
            }
        ]
    }
]

And from this, we want to run a SELECT to return a list of all products whose name contains ‘tape’. We thought the best way to acheive this would be to ‘flatten’ or ‘ungroup’ the list to produce a single list with all items and object elements eg:

[
  {
    "name": "Duct tape",
    "category": "Utility"
  },
  {
    "name": "Swiss army knife",
    "category": "Tools"
  },
  {
    "name": "Glue",
    "category": "Utility"
  }
]

From this, we could run our SELECT function to filter the list, and then use the GROUP function to regroup the results by category eg:

[
    {
        "category": "Utility",
        "products": [
            {
                "name": "Duct tape"
            }
        ]
    }
]

Is there another way that we can’t find to run a select on a lists within a list of objects?

Hi @Chris_Revell, you can use the following formula to achieve that:

MAP<category>(data.productList, SET_KEY(category, 'products', SELECT<product>(category.products, CONTAINS(product.name, 'tape'))))

→ MAP over all categories. Use SET_KEY to transform the products list to only contain those items for which the SELECT statement (name CONTAINS ‘tape’) is true.

Thanks Mari!! Thank works beautifully!

I have never understood the notation in the documentation. It seems to create some sort of temporary object that you can perform functions on, although i’m still confused. Do you happen to know of a documentation page or forum post that explains how we can use the notation in our app as i see it as an option on many of the appgyver functions.

Thanks Again!!!

1 Like

Hi, I unfortunately don’t think there’s a piece of documentation on it, but the notation is an alias. The default alias to refer to an item in the original list is item. However if you are using several nested formulas that’s not going to work, because item will have multiple references. That’s why I’ve added the category and product aliases separately.