Spreadsheet Practice

How to rename column headers in a QUERY in Google Sheets

Google Sheets formula

=QUERY(A1:F13,"select B, sum(E), sum(F) group by B label B 'Sales rep', sum(E) 'Units', sum(F) 'Revenue'",1)

Add a label clause at the end, one name per column: =QUERY(A1:F13,"select B, sum(E), sum(F) group by B label B 'Sales rep', sum(E) 'Units', sum(F) 'Revenue'",1).

Result on the example
a 6-row list that spills from H1 in H1
Excel
See below

See it work

The formula is already in H1. Change any input and the result updates, or edit the formula to experiment.

How it works

Without a label clause, totals get headers like "sum Units" and "sum Revenue". label takes pairs of a column or expression and the new header in single quotes. Each expression must be written exactly as in select: sum(E), not E.

=QUERY(A1:F13,"select B, sum(E), sum(F) group by B label B 'Sales rep', sum(E) 'Units', sum(F) 'Revenue'",1)

Result{6 rows × 3 cols} "Sales rep", "Units", "Revenue", "Ana Ruiz", …

  1. A1:F1313 rows × 6 cols: "Date", "Rep", "Region", "Product", …

    A range: 13 rows × 6 columns.

  2. QUERY(A1:F13,"select B, sum(E), sum(F) group by B label B 'Sales rep', sum(E) 'Units', sum(F) 'Revenue'",1){6 rows × 3 cols} "Sales rep", "Units", "Revenue", "Ana Ruiz", …

    QUERY: Runs a SQL-like query: select, where, group by, order by, limit, label.

    • dataA1:F1313 rows × 6 cols: "Date", "Rep", "Region", "Product", …
    • query"select B, sum(E), sum(F) group by B label B 'Sales rep', sum(E) 'Units', sum(F) 'Revenue'"
    • headers1

In Excel

Excel has no QUERY function. Build the result with a formula and stack your own headers on top: =VSTACK({"Sales rep","Units","Revenue"},…).

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen to use it
=QUERY(A1:F13,"select B, sum(E), sum(F) group by B",1)spills 6 × 3Different resultThe default headers, for comparison. Headers read Rep, sum Units and sum Revenue.

Common mistakes

  • label goes after order by, limit and offset, and before format. Anywhere else the query fails.
  • Labelling a column that isn't selected returns an error. Check that every expression in label also appears in select.
  • An empty label, sum(F) '', clears that header but still leaves the header row in place.

Try it yourself

Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.

Rename column headers in a QUERY

In H1, use QUERY to total the units and revenue per rep, with the headers Sales rep, Units and Revenue.

Questions

How do I rename just one column?

Label only that one: label sum(F) 'Revenue'. The others keep their headers.

Can label use a cell value?

Yes, by joining it in: "… label sum(F) '"&I1&"'".

Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine.