Google Sheets QUERY: Apply a Format
FORMAT
It is possible to format numerical values, dates, and times returned by the QUERY function by specifying the data format.
Apply a format to a column
To change the format of the registration date (B), add FORMAT at the end of the query followed by the relevant column and the format in single quotes:
=QUERY(DB!A1:G15,"SELECT * FORMAT B 'mmmm d yyyy'")
Or to apply (for example) a currency format to column E, enter:
=QUERY(DB!A1:G15,"SELECT * FORMAT E '$#,##0.00'")
Apply a format to the result of a function
The following example displays the sum of messages (E) for each rank (D):
=QUERY(DB!A1:G15,"SELECT D, SUM(E) GROUP BY D")
To apply (for example) a number format to 2 decimals (with thousands separator) to the sum of messages, specify the format of the SUM function:
=QUERY(DB!A1:G15,"SELECT D, SUM(E) GROUP BY D FORMAT SUM(E) '#,##0.00'")
To additionally apply a custom format to the ranks (D), add this additional format to the sequence:
=QUERY(DB!A1:G15,"SELECT D, SUM(E) GROUP BY D FORMAT SUM(E) '#,##0.00', D 'RANK 0'")