Google-sheets – Query with sums and 2 columns on the left

google sheetsgoogle-sheets-query

I have problem with the query:

=Query(Raw_Data!J$2:$BL,"Select J, Sum(U),Sum(V),Sum(W),Sum(X),Sum(Y),Sum(Z),Sum(AA),Sum(AB),Sum(AC),Sum(AD),Sum(AE),Sum(AF) where J contains 'CUS' and (AL='1-Revenues') and (AJ='Not CAPEX' or AJ='Unconfirmed CAPEX') and (AH='Not Intercompany') and (AM='2-Learn') and (M='2-B2B') Group By J",0)

That works fine, I get almost 90% of what I need BUT, basically, I've another column in the range (P), that I wanna see on the right of column J.

The situation is like this:

J .  P

A . 1
B . 2
C . 2
D . 3
E . 4
F . 1

I'd like to see Column P results on the right of Column J (that I already get with the above formula), then the sums (that already came out from that formula).

How can I add column P?

Best Answer

Add P after J both on the Select clause and the the Group By clause using a comma as separator:

=Query(Raw_Data!J$2:$BL,"Select J, P Sum(U),Sum(V),Sum(W),Sum(X),Sum(Y),Sum(Z),Sum(AA),Sum(AB),Sum(AC),Sum(AD),Sum(AE),Sum(AF) where J contains 'CUS' and (AL='1-Revenues') and (AJ='Not CAPEX' or AJ='Unconfirmed CAPEX') and (AH='Not Intercompany') and (AM='2-Learn') and (M='2-B2B') Group By J, P",0)

Related