# Query with sums and 2 columns on the left

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?

• Hi Simone, it would greatly help if you could provide a link to a dummy sheet with th query implemented. Also, would it be possible to simplify your question to show what exactly you're struggling with? It's a little specific at the moment making it hard to understand what exactly you're trying to achieve. – Cornelius Roemer Oct 15 '19 at 19:30
• Using your data (output of the query = 2 columns), just add another `Query` on top of it like this `=query(ORIGINAL_FORMULA(),"SELECT Col2,Col1")` to swap the columns. – pjmg Oct 16 '19 at 12:54

`=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)`