Formualizer Docs

GROUPBY

Groups rows by key fields and returns aggregated values as a spilled table.

GROUPBY summarizes one or more value columns using a selected aggregation function.

The Formualizer engine in this repository at 0.15.0 plus unreleased changes computes the example results. Known differences from Excel are listed on this page.

Syntax

=GROUPBY(row_fields, values, function, [field_headers], [total_depth], [sort_order], [filter_array], [field_relationship])

Arguments

ArgumentTypeRequiredDefault
row_fieldsrange (range)Required—
valuesrange (range)Required—
functionanyRequired—
field_headersnumberOptional1
total_depthnumberOptional0
sort_ordernumberOptional0
filter_arrayvalueOptional—
field_relationshipvalueOptional—

Differences from Excel

Formualizer accepts a text aggregation name. Excel’s aggregation function argument is unsupported. A filter array also returns #VALUE! in Formualizer. Formualizer defaults total_depth to 0 (no totals). Excel automatically adds a grand total and, where possible, subtotals.

Remarks

  • row_fields and values must have the same row count.
  • Aggregation can be supplied as text (for example "SUM") or numeric code.
  • Use field_headers, total_depth, and sort_order to control the result layout.
  • Output is dynamic-array shaped and may include generated headers or totals.

Error cases

  • Unlike Excel's filter mode, a supplied filter_array returns #VALUE! in Formualizer.
  • A supplied field_relationship with multiple row fields also returns #VALUE!.
  • Invalid aggregation names/codes return #VALUE!.

Examples

Sum each region's sales from columns that include headers.

Formula =GROUPBY({"Region";"East";"East";"West"},{"Sales";10;20;8},"SUM")

Expected result {"East", 30; "West", 8}

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Average each region, omit totals and sort labels in descending order.

Formula =GROUPBY({"East";"East";"West"},{10;20;8},"AVERAGE",0,0,-1,,0)

Expected result {"West", 8; "East", 15}

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Group a single observation into one result row.

Formula =GROUPBY({"East"},{10},"SUM",0,0)

Expected result {"East", 10}

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Every group label must have a corresponding value.

Formula =GROUPBY({"East";"West"},{10},"SUM")

Expected result #VALUE!

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Sum sales by region

Formula =GROUPBY(A1:A4,B1:B4,"SUM",3,0,1)

Input cells
AB
1"Region""Sales"
2"East"100
3"West"80
4"East"50

Expected result {"Region", "Sales"; "East", 150; "West", 80}

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Average with grand total

Formula =GROUPBY(A1:A4,B1:B4,"AVERAGE",3,1,1)

Input cells
AB
1"Team""Score"
2"A"90
3"A"70
4"B"80

Expected result {"Team", "Score"; "A", 80; "B", 80; "Grand Total", 80}

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

FAQ

What shape constraints does GROUPBY enforce?

row_fields and values must have the same number of rows; mismatched heights return #VALUE!.

Can the aggregation function be numeric instead of text?

Yes. GROUPBY accepts either function names (like "SUM") or numeric function codes, and invalid entries return #VALUE!.

Implementation

Engine source

On this page