{"id":"code-work-office-sheets-query-totals","audience":"office","category":"coding","track":"coding","technique":"format","title":"Summarize approved spend by team with one QUERY formula","free":false,"task":"Write one Google Sheets QUERY formula for Summary!A1 that reads Requests!A1:E (row 1 is headers) and returns each team in column B with the total of column C for Approved rows only (column D), biggest total first. The total column must be labeled Total, and the formula must say there is 1 header row. One formula in one code block, then under 25 words outside the code.","materialLabel":"Requests tab preview (attached to your prompt automatically)","material":"REQUESTS tab - office purchase requests (row 1 is headers, new rows added daily)\nA Date | B Team | C Cost | D Status | E Item\n10/01/2026 | Finance | 340 | Approved | Standing desk\n10/02/2026 | Sales | 85 | Pending | Monitor arm\n10/03/2026 | Finance | 40 | Approved | Label maker\n10/06/2026 | Ops | 120 | Denied | Whiteboard\n10/07/2026 | Sales | 65 | Approved | Headset\n10/09/2026 | Ops | 210 | Approved | Shelving\n10/12/2026 | Sales | 410 | Approved | Chairs\n\nNotes:\n- Costs are plain numbers (no $ sign) so they add up.\n- Teams were renamed in September; Sales used to be called Revenue.\n- The Summary tab feeds the monthly budget email.\n- Denied requests are kept for the record.","rules":[{"type":"codeBlocks","count":1},{"type":"maxProseWords","max":25}],"mistakes":[{"title":"Not naming the function","why":"The AI builds a pivot table walkthrough or a pile of SUMIFS instead of one formula.","fix":"Add: \"One QUERY formula for Summary!A1.\"","checks":["r0"]},{"title":"Leaving the output shape open","why":"The AI keeps the ugly default header sum Cost and its own sort order.","fix":"Add: \"Biggest first, label the total column Total.\"","checks":["r1"]},{"title":"Forgetting the header row","why":"QUERY guesses how many header rows there are and sometimes guesses wrong.","fix":"Add: \"1 header row, as the last argument.\"","checks":["r2"]},{"title":"Getting a menu of options","why":"The AI likes to offer two or three versions of the formula, so you're left to pick and test them yourself.","fix":"Add: \"Give one formula only, in one code block, no alternatives.\"","checks":["codeBlocks"]},{"title":"Getting a tutorial","why":"By default the AI explains every part of the code at length, which you then have to scroll past.","fix":"Add: \"After the code, one line under 10 words. Nothing else.\"","checks":["maxProseWords"]}],"promptHints":[{"label":"Names QUERY","patterns":["query"]},{"label":"Sets the sort and label","patterns":["desc","biggest|largest|highest","label","total"]},{"label":"Mentions the header row","patterns":["header","1 header","row 1"]},{"label":"Filters to approved","patterns":["approved"]},{"label":"Asks for one answer only","patterns":["\\b(one|single|1)\\s+(formula|code block|block|version)","only one","no (alternatives|options|other versions)"]}],"hint":"Say exactly what the result table should look like: which rows count, the sort order and the column label.","rubricLabels":["Uses QUERY on Requests!A1:E with a select of B and sum(C), where D = 'Approved', group by B","Orders by sum(C) desc and labels the sum column 'Total' (label sum(C) 'Total')","Sets the header argument to 1 (the last QUERY argument)"]}