Search code examples
google-sheetsgoogle-sheets-formulagoogle-query-language

Importrange with query and reorder some of the columns on import Google Sheets


I have a sheet with 52 columns from A to AZ. I am importing these with Importrange and query to a different file.

I want to move Column X to the first column on the import

Is this possible to do without listing the order of all 52 columns in the query?

=ARRAYFORMULA(
  QUERY(
    {
      TRIM(IFERROR(IMPORTRANGE("1Qe####","Sheet1!A2:AZ"&counta(importrange("1Qe###","Sheet1!A2:AZ")))))
    },
    "select col24, col1,...,col52",1
  )
)

Solution

  • Here's one approach and change it accordingly:

    =QUERY(IMPORTRANGE("SPREADSHEET ID","Sheet1!A2:AZ"),"Select Col29"&", "&SUBSTITUTE(JOIN(", ",INDEX("Col"&SEQUENCE(52))),", Col29",""))