Google Sheets QUERY: Modify Headers

LABEL

It is possible to modify the headers returned by the QUERY function using LABEL.

Modifying the headers is particularly interesting when an aggregate function is used and returns the header "sum Messages", for example.


Change the header of a column

To change the name of a column's header, add LABEL, followed by the relevant column and the new name in single quotes:

=QUERY(DB!A1:G15,"SELECT * LIMIT 6 LABEL C 'First Name'")
google sheets function query select label header

To rename multiple columns, add them in sequence:

=QUERY(DB!A1:G15,"SELECT * LIMIT 6 LABEL A 'A', B 'B', C 'C', D 'D', E 'E', F 'F', G 'G'")
google sheets function query label columns

Change the header returned by a function

The example below uses the result of the operation A % 2 which returns 0 for even numbers and 1 for odd numbers (% = modulo = returns the remainder of a division).

The following query groups the data based on column A (even or odd number) and adds the number of messages (E) from each group:

=QUERY(DB!A1:G15,"SELECT A % 2, SUM(E) GROUP BY A % 2")
google sheets function query label sum modulo

To modify the headers of these 2 columns, enter:

=QUERY(DB!A1:G15,"SELECT A % 2, SUM(E) GROUP BY A % 2 LABEL A % 2 'Even / odd', SUM(E) 'Total messages'")

google sheets function query label sum modulo group png

It is also possible to remove the headers and assign them an empty value:

=QUERY(DB!A1:G15,"SELECT A % 2, SUM(E) GROUP BY A % 2 LABEL A % 2 '', SUM(E) ''")
google sheets function query label empty