2

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?

0

2 Answers 2

1

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:

  • The formula recreates the table filled with your data, replacing any blank cells with 0, so you won't need to put in zeroes in your spreadsheet directly. Afterwards, it is used with the query function to essentially sum the total of your values.

Output

Name Sum
Jack 150
Jill 248
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Drew. The help for the arrayformula function does not describe it very well. Or maybe it's just seeing an example that does something I do understand, that made it understandable :)
1

You may also try-

=QUERY({A:A,BYROW(B:C,LAMBDA(r,SUM(r)))},"select Col1, sum(Col2) where Col1 <>'' group by Col1",0)

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.