# Calculate Percentage with QUERY on Google Sheets

I have a Google Sheets database like this:

``````   Name  | Value  | Answer
A   |  100   |   Y
B   |  200   |   N
C   |  10    |   Y
A   |  100   |   N
A   |  1000  |   Y
B   |  50    |   Y
B   |  200   |   N
``````

And I want, by using `QUERY`, to get the total percentage of "Answer" like this:

``````Answer | %Total
Y    |  57%
N    |  42%
``````

And the percentage of Y and N per name:

``````Name | Sum  | Count |  %Y  | %N
A    | 1200 |   3   | 28%  | 71%
B    |  450 |   3   | 14%  | 85%
C    |  10  |   1   | 14%  | 85%
``````

Here's what I have so far:

``````=QUERY(Data!A1:C8;"SELECT A, SUM(B), COUNT(B) group by A")
``````

I got the `SUM` and the `COUNT`, but couldn't figure how to get the percentage as cited above. Could somebody with more experience please help with that?

• I think google QUERY alone isn't capable of doing what you are trying to do. For the first percentage, you can try to use =query(A1:C8,"select C, count(C) group by C") and then apply a formula to calculate %s.
– Oren
Commented Dec 11, 2018 at 21:14
• Thanks for the reply Oren, I'm not sure if it's possible to do it using just QUERY indeed. Your idea works well, I think I'll do something this way. Commented Dec 12, 2018 at 19:47

``````=QUERY(D:D, "SELECT D, COUNT(D)/"&COUNTA(D:D)-1&" WHERE D IS NOT NULL GROUP BY D", 1)