10

I have a two column table where one column is some sort of key where duplicates are allowed and the other column includes amounts.

I then have the following formula somewhere else on the sheet:

=QUERY(A1:B, "SELECT SUM(A) GROUP BY B")

The results of that query begin with 'sum', then a blank line, then the summed values:

spreadsheet with sum

How can I modify the existing formula so that I do not have the 'sum' header and the blank line (if I can at all)? I want to avoid using multiple cells to create the desired affect and I want to avoid scripting.

1 Answer 1

15

To suppress the header, end the query string with label sum(A) ''.

The blank spot below the header comes up because the column B, besides the letters a,b,c, also contains a bunch of blank cells, which form a group of their own. Since you don't want them, add the clause where B<>''.

End result:

=query(A1:B, "select sum(A) where B<>'' group by B label sum(A) ''")

(Case doesn't matter: I prefer lowercase because more text fits into the same horizontal space.)

2
  • Thanks. That works great. For some reason though, when I did <> '' for certain columns in my real project, I kept getting N/A (no results). The columns I tried were the amount column, a date column, and a derived MONTH column (which is actually how I will be grouping). So I just used a column that will always be a non-empty description. Commented Jan 7, 2016 at 17:06
  • Try B not null instead of B <> ''.
    – user79865
    Commented Jan 7, 2016 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.