Google-sheets – importrange with query not working properly

google sheetsgoogle-sheets-queryimportrange

I'm trying to import a column from a separate sheet and add a query to it.

Im using:

=QUERY(ImportRange("URL","SHEETNAME!c:f"),"select Col1 where Col4 contains 'statements' ")

I've been using this for years and its always ALWAYS worked. Now it suddenly doesn't work. The importing works but the query is not working and it's actually taking the data and transposing it… Any ideas why my formula isn't working?

Best Answer

When the output of query changes in a strange way just because of different data, there are two likely reasons:

  1. Mis-identification of header rows. query tries to guess what rows contain data, and what rows are headers for that data. Solution: provide the third argument with the correct number of header rows, query(range, "select ...", 1).

  2. Mixed data types. Each data column is interpreted as being of some type: text, numbers, dates. If these are mixed together, the type is determined by majority. The other entries are either converted to majority type, or discarded altogether. The solution is to avoid mixed data.

In this case, it was the first reason.