Powered By GitBook
GROUP
Groups items in a list

Description

Groups items in the given list using two formulas: one that defines the grouping criteria for each item, and one that creates the group items returned by this function.
First the grouping criteria formula is evaluated for each item in the list. All the items that evaluate to the equal _group key_ are grouped together.
Then the latter formula is evaluated for each _group_. You can use key in the formula to get the grouping key of the current group, and items to access all the items belonging to the current group.

Function signature

1
GROUP(list: Array, groupcriteria: Function, groupingformula: Function) => Array
Copied!
Parameter
Description
List
List of items to group
Group criteria
Formula that returns a group key for the current item
Grouping formula
Formula that returns the final value for each "group" in the result list

Examples

1
allProducts = [
2
{
3
"name": "Duct tape",
4
"category": "Utility"
5
},
6
{
7
"name": "Swiss army knife",
8
"category": "Tools"
9
},
10
{
11
"name": "Glue",
12
"category": "Utility"
13
}
14
]
Copied!
Formula
Return value
GROUP(allProducts, item.category, { category: key, products: items })
[{"category":"Utility","products":[{"name":"Duct tape","category":"Utility"},{"name":"Glue","category":"Utility"}]},{"category":"Tools","products":[{"name":"Swiss army knife","category":"Tools"}]}]
GROUP(allProducts, item.category, key + " category contains " + COUNT(items) + " product(s)")
["Utility category contains 2 product(s)","Tools category contains 1 product(s)"]
GROUP<product, index, category, products>(allProducts, product.category, { category: category, count: COUNT(products) })
[{"category":"Utility","count":2},{"category":"Tools","count":1}]
Last modified 11mo ago
Export as PDF
Copy link