Search code examples
google-sheetsgoogle-query-language

Prevent blank column and line in the google query result


Doing the following query = QUERY(A2:C, "select B, avg(C) group by B pivot A") returns a correct summary of my source data. However, there is blank line and a blank column in the result (see example). How to get rid of them? I can deal with the blank line using offset 1 but what about the column?

Also, using A2:C11 to specify the data, there are no blank lines or columns. But then when data gets added at the end of the source range, it doesn't get included in the query result (obviously). How to prevent the blank line and column?


Solution

  • You probably have some blank rows in your source range. Try:

    = QUERY(A2:C, "select B, avg(C) where C is not null group by B pivot A")