Table.Group

Syntax

Table.Group(table as table, key as any, aggregatedColumns as list, optional groupKind as nullable number, optional comparer as nullable function) as table 

About

Groups the rows of table by the values in the specified column,key, for each row. For each group, a record is constructed containing the key columns (and their values) along with any aggregated columns specified by aggregatedColumns. Note if multiple keys match the comparer, different keys may be returned. This function cannot guarantee to return a fixed order of rows. Optionally, groupKind and comparer may also be specifed.

Example 1

Group the table adding an aggregate column [total] which contains the sum of prices ("each List.Sum([price])").

Table.Group(Table.FromRecords({[CustomerID= 1, price = 20], [CustomerID= 2, price = 10], [CustomerID= 2, price = 20], [CustomerID= 1, price = 10], [CustomerID= 3, price = 20], [CustomerID= 3, price = 5]}), "CustomerID", {"total",each List.Sum([price])})
CustomerID total
1 30
2 30
3 25