Search code examples
google-sheets

Google Sheet Query - Repeating certain Columns


I have a Google Sheet with Data tab and Report tab. I use Query in Report tab and the range is from the Data tab. I learned that to repeat certain columns you'd have to combine more than 1 query inside a curly bracket. (Sample below, for the report I would need column V to AA to be repeated on the report).

={QUERY(Data!$A:$AG,"select D,C,AF,V,W,X,Y,Z,AA where AF=ForReport"),QUERY(Data!$A:$AG,"select V,W,X,Y,Z,AA,F,J where AF=ForReport")}

Is this method the best method and safe? I'm worried that the result from each query could fail to line-up or match. I didn't sort and both queries use the same condition except the columns to select but it's hard to prove if combined queries messed up the report data.


Solution

  • Your formula looks fine to me. You could also use CHOOSECOLS.

    =QUERY(CHOOSECOLS(DATA!A:AG,4,3,32,22,23,24,25,26,27,22,23,24,25,26,27,6,10),"where Col3='ForReport'")