SheetRocks
Documentation/Formulas/GROUPBY

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]]
A B
1 North 100
2 South 200
3 North 150
4 South 75

Group products by category and count

=GROUPBY(A1:B3, COL[1], COUNT(COL[2]))
Result ⇒ Array: [["Electronics", 2], ["Clothing", 1]]
A B
1 Electronics Phone
2 Clothing Shirt
3 Electronics Laptop

Group employees by department and average salary

=GROUPBY(A1:B4, COL[1], AVERAGE(COL[2]))
Result ⇒ Array: [["IT", 75000], ["HR", 62500]]
A B
1 IT 70000
2 HR 60000
3 IT 80000
4 HR 65000

Related Functions

Other Data functions:


← Back to Formula Reference