Google Sheets: Error – Query completed with an empty output.

Standard

I recently came across this error when using the QUERY keyword in Google Sheets.

Now my result set is actually empty, so I don’t really think this should be an error, but the people at Google who probably know better than me think it is.

Here’s what my formula looks like, as you can see I’m unioning two different result sets:

As you can see there are 2 QUERYs here, one below the other. The issue is that if either return nothing, then the formula will beeak and I’ll get the below error:

And digging even further by removing the QUERYs one at a time I get this error:

IFERROR to the rescue!

If we just surround the QUERYs with IFERROR(QUERY(),””) it will work fine if we only have 1 QUERY or if both QUERYs return nothing. However if one QUERY returns a set and the othr doesn’t we’ll run into issues because the sets in the union are different widths.

To get around this problem we can simply return an empty array that matches the size of the array we’re expecting from our queries:

As you can see I just use IFERROR(QUERY(A:A, “SELECT A, B, C, D”), {“”,””,””,””,}) and the IFERROR will return a nice empty set when there’s a problem.

There should probably be a way to handle empty result sets in the QUERY function itself, because the solution above will mask issues where there’s an actual real problem with the QUERY and not just an empty result set.