Search code examples
google-sheetsgoogle-sheets-formula

Google Sheets QUERY IMPORTRANGE is merging first and second rows


In a company that I work for, I have two Google Sheets. In one of them (let's call it "Destination"), I am trying to use QUERY+IMPORTRANGE to bring the values from the other (let's call it "Origin").

My problem is that in the first row of Destination, the values of the cells are a merger of the values of the first and second rows of Origin.

For example, the value in cell B1 of Destination should be the value of cell B1 in Origin. However, it is actually the values of B1 and B2 of Origin. The same happens for every single cell in the first row.

  • Origin B1: milk
  • Origin B2: water
  • Destination B1 (desired value): milk
  • Destination B1 (value that is appearing): milk water

The only problem is with the first two rows of Origin. All the other rows are fine (meaning that row 2 in Destination is row 3 of Origin, row 3 in Destination is row 4 of Origin, and so on).

I am using the following formula:

=QUERY( {IMPORTRANGE("URL";"'Sheet1'!A1:CW")} ; "Select * where Col1 is not null")

I have discovered that when I use A1:AO as the interval in IMPORTRANGE, the problem doesn't happen. However, when I use it from A1:AP and onwards, the problem appears.

Could someone help me with this problem?


Solution

  • change your query to specify 1 for the header parameter:

    =QUERY( {IMPORTRANGE("URL";"'Sheet1'!A1:CW")} ; "Select * where Col1 is not null",1)
    

    or 0 if i'm misunderstanding the data layout...

    =QUERY( {IMPORTRANGE("URL";"'Sheet1'!A1:CW")} ; "Select * where Col1 is not null",0)