Given a Google Sheet with the following data:
A | B | C |
---|---|---|
Jack | 150 | |
Jill | 10 | 33 |
Jill | 205 |
If I enter this function:
=query(A1:C3, "select A, sum(B) + sum(C) group by A", 0)
I get the following in A5
:
sum(sum sum ) | |
---|---|
Jack | |
Jill | 248 |
What I expected was:
sum(sum sum ) | |
---|---|
Jack | 150 |
Jill | 248 |
Note that both C1
and B3
are empty cells.If I set C1
to 0, it works as expected. Setting B3
to 0 has no effect.
I would rather not clutter up my spreadsheet with a bunch of zeros. Any ideas?
Try the following:
=query(arrayformula({A1:A3, n(B1:C3)}), "select Col1, sum(Col2)+sum(Col3) group by Col1 label Col1'Name', sum(Col2)+sum(Col3)'Sum'")
How it works:
Output
Name | Sum |
---|---|
Jack | 150 |
Jill | 248 |