# Google sheet query to combine values

From various examples I've hacked together a pretty neat aggregation function which gives me an overview on which activity (strings in G) I've spent non-billable work hours (numbers in E) or billable (numbers in E) hours of work.

``````=query(E35:G232, "select G, sum(E), sum(F) where G != '' group by G order by sum(F) desc label G 'activity', sum(E) 'work hours', sum(F) 'billable hours'")
``````

So this might give me:

``````Development |  5 | 12
Marketing   | 14 |  5
``````

What I've tried, but so far failed, to do now is getting this same list with the combined hours per activity, and also sort it by that combined number. I tried combining the select with combining the sum of columns, but that gives me an error:

``````=query(E35:G232, "select G, sum(E), sum(F), sum(E:F) where ...
``````

How can I further combine the grouped values to get the overall values per activity to get something like this, additionally sorted by highest combined?

``````Marketing   | 14 |  5 | 19
Development |  5 | 12 | 17
Admin       |  0 |  2 |  2
``````
• You can't. Use a double query: `=query(query())` – TheMaster Jul 9 '18 at 14:09
• Or just add a formula next to the query results – Rubén Jul 9 '18 at 17:17
• @I'-'I Can you give me an example? I suppose the subquery would be generating a col of combined values in this case? – kontur Jul 11 '18 at 8:40
• @Rubén The query affects the sorting, and I would like to sort all 4 columns in rows with combined hours highest. Can a formula do that, how? – kontur Jul 11 '18 at 8:41

``````=QUERY(query(E35:G232, "select G, sum(E), sum(F) where G != '' group by G order by sum(F) desc label G 'activity', sum(E) 'work hours', sum(F) 'billable hours'"),"Select Col1,Col2,Col3,Col2+Col3 order by Col2+Col3",1 )