Google Sheets: How to replace text in column header?
I have a query like this =QUERY(B2:C9; "select (C * 100 / B) - 100")
in my Google Sheets. What is displayed as a column header is:
difference(quotient(product(100.0()))100.0())
.
I want to put a human readable description there instead.
How can I achieve this?
Solution 1:
=QUERY(B2:C9;"select (C*100/B)-100 label (C*100/B)-100 'Value'")
https://developers.google.com/chart/interactive/docs/querylanguage#Label
Solution 2:
Remember there is a trick there.
Working example of the query:
"SELECT C, COUNT(C), AVG(G), AVG(E) GROUP BY C ORDER BY COUNT(C) DESC LABEL COUNT(C) 'My count' FORMAT AVG(G) '##0.00', AVG(E) '##0.00'"
Not working example of the query:
"SELECT C, COUNT(C) LABEL COUNT(C) 'My count', AVG(G), AVG(E) GROUP BY C ORDER BY COUNT(C) DESC FORMAT AVG(G) '##0.00', AVG(E) '##0.00'"
Also not working example of the query:
"SELECT C, COUNT(C), AVG(G), AVG(E) GROUP BY C ORDER BY COUNT(C) DESC FORMAT AVG(G) '##0.00', AVG(E) '##0.00' LABEL COUNT(C) 'My count'"
It works ONLY if it's placed in the correct order with other commands.
Solution 3:
It's counter-intuitive, but you must define your relabeled column TWICE; once in the "SQL" string, and then append the label
clause to the end of the SQL string.
So, if you want to select A, B, C with "B" being labeled as "Foo", you would do this:
=QUERY(B2:C9;"select A, B, C label B 'Foo' ")
If you're doing calculations, be careful to exactly match the SQL string definition and the label definition. For example:
=QUERY(B2:C9;"select A, B*2, C label B*2 'Foo' ")
https://developers.google.com/chart/interactive/docs/querylanguage#Label