Google Sheets Query Sum Multiple Columns: How-To

How-to basics · Updated November 23, 2026

To sum multiple columns in Google Sheets with a QUERY function, you list each column you want to sum in the SELECT clause and wrap each one in the SUM() function, separating them with commas. For example, with data in columns A (names), B (sales), C (returns), and D (profit), the formula =QUERY(A:D, "SELECT A, SUM(B), SUM(C), SUM(D) GROUP BY A LABEL SUM(B) 'Total Sales', SUM(C) 'Total Returns', SUM(D) 'Total Profit'") returns one row per name with the sums for each column.

How the QUERY Function Handles Multiple Columns

QUERY uses a Google Visualization API query language, not standard spreadsheet formulas. When you write SUM(B), it aggregates that single column. To sum multiple columns, you repeat the SUM() function for each column you want. The key is that the GROUP BY clause must include every non-aggregated column in the SELECT clause. If you select column A (names) and also sum columns B, C, and D, you must group by A. If you omit GROUP BY, QUERY returns a single total row for each summed column, which is useful when you want overall totals without grouping.

Here’s a concrete example. Suppose A1:D5 contains:

  • A: Product names (Apples, Bananas, Cherries)
  • B: Units sold
  • C: Returns
  • D: Net profit

To get total units, returns, and profit per product, use =QUERY(A:D, "SELECT A, SUM(B), SUM(C), SUM(D) GROUP BY A"). The result will show each product name with three numeric columns. To get grand totals across all products, use =QUERY(A:D, "SELECT SUM(B), SUM(C), SUM(D)") – no GROUP BY needed.

Using SUM with WHERE to Filter Before Summing

You can add a WHERE clause to sum only certain rows. For instance, to sum sales and profit only for products with more than 10 units sold, write: =QUERY(A:D, "SELECT SUM(B), SUM(D) WHERE B > 10"). When using WHERE with multiple columns, you can reference any column. Note that if you filter on a text column, you must enclose the value in single quotes, like WHERE A = 'Apples'. For numeric comparisons, no quotes are needed.

Be careful with dates: they must be formatted as DATE 'YYYY-MM-DD' inside the query string, for example WHERE A >= DATE '2024-01-01'. This is a common source of errors because plain text dates won’t match.

Labeling the Summed Columns

By default, QUERY labels summed columns as sum (e.g., sum for SUM(B)). To give meaningful headers, use the LABEL clause. The syntax is LABEL SUM(B) 'Total Sales', SUM(C) 'Total Returns'. You must list each summed column you want to rename. If you have multiple SUM columns, separate each label with a comma. For example: =QUERY(A:D, "SELECT A, SUM(B), SUM(C) GROUP BY A LABEL SUM(B) 'Total Units', SUM(C) 'Returns'"). This makes the output easier to read, especially when you have many columns.

What About SUM of a Calculated Column?

Sometimes you need to sum a column that doesn’t exist in the source, like a profit margin. QUERY cannot directly sum an expression like SUM(B*C) in the SELECT clause. Instead, you must sum the product first: SELECT SUM(B*C) is not valid. However, you can sum a calculated value by using the SUM function on a multiplication inside the SELECT clause? Actually, the query language supports arithmetic in SELECT, but not inside SUM. The correct approach is to compute the column in the spreadsheet first (e.g., add a helper column E with formula =B2*C2) and then sum that column in QUERY. Alternatively, you can use a different function like ARRAYFORMULA with SUM, but QUERY itself cannot sum a derived expression directly. So if you need to sum revenue (price × quantity), add a helper column.

Common Errors and How to Fix Them

  • “Unable to parse query string” – Usually a missing comma between SELECT items, or a missing GROUP BY for non-aggregated columns. Check that every column in SELECT without SUM() appears in GROUP BY.
  • “Column A is not in the GROUP BY” – If you select A and also SUM(B), you must add GROUP BY A. If you only want totals, remove A from SELECT.
  • Mixed data types – QUERY expects consistent types. If a column has numbers stored as text, SUM may return 0 or an error. Use VALUE() in a helper column or convert the data using Data > Split text to columns.
  • Quotes in WHERE – Text values need single quotes, not double quotes. Double quotes are used to delimit the whole query string. For example, WHERE A = 'Apples' is correct; WHERE A = "Apples" breaks.

Comparing QUERY SUM to SUMIFS

For summing multiple columns, you have alternatives. The QUERY function is powerful but can be slow on large datasets. The SUMIFS function can sum a single column based on multiple criteria, but it cannot sum multiple columns at once. To sum multiple columns with SUMIFS, you would need to write separate formulas for each column and add them, like =SUMIFS(B:B, A:A, "Apples") + SUMIFS(C:C, A:A, "Apples"). QUERY is more concise when you need several sums in one output. For simple cases with one or two criteria, SUMIFS may be faster and easier to debug. For complex grouping or multiple aggregated columns, QUERY is superior.

Performance and Large Data Sets

QUERY recalculates each time data changes, which can be slow if your sheet has thousands of rows. To improve performance, limit the range in the QUERY reference, e.g., =QUERY(A:D, ...) instead of full columns like A:D is fine, but if you have data in rows 1 to 5000, use A1:D5000 to avoid scanning empty rows. Also, avoid using QUERY in array formulas with ARRAYFORMULA. For very large data, consider using Pivot Tables or the FILTER function combined with SUM, which may be more efficient. Additionally, QUERY does not handle blank cells well; if you have blanks in numeric columns, it might ignore them or cause errors. Use IFERROR to handle potential errors.

Frequently Asked Questions

Can I sum two columns into one total with QUERY? Yes, you can sum two columns into a single total by adding them in the SELECT clause, like SELECT SUM(B) + SUM(C). This returns one column that is the sum of both. For example, =QUERY(A:D, "SELECT SUM(B) + SUM(C)") gives a single total. Note that this adds the sums, not row-by-row. If you need row-by-row addition, use a helper column.

How do I sum columns with different data types? QUERY requires consistent types. If one column contains numbers and another contains text, you cannot sum them together. Convert text to numbers using the VALUE function in a helper column, or use QUERY’s VALUE() function? Actually, QUERY does not have a VALUE function. So create a helper column with =VALUE(C2) and sum that.

Why does my QUERY return 0 for sums? This usually happens when the column contains text-formatted numbers. Check the column type by selecting the column and looking at Format > Number. If it says “Plain text”, convert to numbers by selecting the column, then Format > Number > Number. Alternatively, use a helper column with =A2*1 to force numeric conversion.

Can I use QUERY to sum columns based on a dropdown selection? Yes, you can reference a cell containing the column letter. For example, if cell F1 contains “B”, you can use =QUERY(A:D, "SELECT SUM(" & F1 & ")"). But this is fragile. A better approach is to use INDIRECT to reference the column range, but QUERY cannot take a dynamic column reference directly. You can build the query string using concatenation, but be careful with injection. For most cases, it’s simpler to use SUMIF with a dynamic condition.

Is there a limit to the number of columns I can sum in QUERY? No hard limit, but practical limits exist. QUERY can handle many columns, but performance degrades with more than a few dozen. Also, the query string length is limited (around 5000 characters). For summing many columns, consider using a Pivot Table instead.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.