GROUPBY
Groups data by a key and applies an aggregator function to each group
Syntax
GROUPBY(range, key, aggregator)
Arguments
| Argument |
Description |
Required |
range |
The range of data to group |
Required |
key |
Lambda expression to determine the grouping key (e.g., COL[1]) |
Required |
aggregator |
Lambda expression to aggregate each group (e.g., SUM(COL[4])) |
Required |
Examples
Group sales by region and sum amounts
=GROUPBY(A1:B4, COL[1], SUM(COL[2]))
Result ⇒
Array: [["North", 250], ["South", 275]]
| North |
100 |
| South |
200 |
| North |
150 |
| South |
75 |
Group products by category and count
=GROUPBY(A1:B3, COL[1], COUNT(COL[2]))
Result ⇒
Array: [["Electronics", 2], ["Clothing", 1]]
| Electronics |
Phone |
| Clothing |
Shirt |
| Electronics |
Laptop |
Group employees by department and average salary
=GROUPBY(A1:B4, COL[1], AVERAGE(COL[2]))
Result ⇒
Array: [["IT", 75000], ["HR", 62500]]
| IT |
70000 |
| HR |
60000 |
| IT |
80000 |
| HR |
65000 |
Related Functions
Other Data functions:
- CHOOSE - Uses index to return a value from the list of value arguments
- COLUMN - Returns the column number of the current cell context.
- DROP - Drops the first N rows and optionally first N columns from an array. Returns an error if the result would be empty.
- FILTER - Returns a filtered array containing only rows that match the criteria
- HLOOKUP - Returns the corresponding value from the specified row of table which matches exactly or approximately to the first row of the table.
- HSTACK - Horizontally stacks arrays by appending columns
- INDEX - Returns a cell value from a list or table based on its column and row numbers.
- LAST - Returns the last N rows and optionally last N columns from an array. Returns an error if the result would be empty.
- MAP - Processes each row in an array with a formula including a COL or CELL keyword and returns it as a 2D array.
- MATCH - Returns the position of the item/lookup_value in the lookup_array or range.
- PICK - Selects specific columns from an array using column numbers or header names
- ROW - Returns the 1-indexed row number of the current cell
- SEQUENCE - Returns the list of generated sequential numbers in an array.
- SORT - Sorts the values in a range or array.
- TAKE - Returns the first N rows and optionally first N columns from an array. Returns an error if the result would be empty.
- TRANSPOSE - Returns the result after transposing the rows and columns of an array or range.
- UNIQUE - Returns a list of unique values in a list or range.
- VLOOKUP - Returns a value from a table by looking up a value in the first column and returning a value from the specified column
- VSTACK - Vertically stacks arrays by appending rows
← Back to Formula Reference