Google Sheets QUERY: Blank, Null and Empty-String Conditions

Filter blank and non-blank rows in Google Sheets QUERY, including is null, is not null, empty strings and formulas that display blank values.

Use is null to return blank rows in a Google Sheets QUERY, and is not null to exclude them.

=QUERY(A1:C, "select * where A is not null", 1)

This returns rows where column A contains a value.

Return rows where a column is blank

=QUERY(A1:C, "select * where B is null", 1)

Return rows where a column is not blank

=QUERY(A1:C, "select * where B is not null", 1)

The final argument is the number of header rows in the source range. Use 0 when the range has no header and 1 for one header row.

Combine null conditions with other criteria

=QUERY(A1:D, "select A, B, D where B is not null and D > 0", 1)

Use parentheses when combining alternatives:

=QUERY(A1:D, "select * where (B is null or C is null) and D > 0", 1)

Blank cells versus empty strings

A formula such as =IF(A2="","",A2) displays a blank result but still exists in the cell. Different Google Sheets functions do not always treat this like a truly empty cell.

When QUERY does not behave as expected, create a clean helper column:

=ARRAYFORMULA(IF(LEN(TRIM(A2:A))=0,,A2:A))

This normalises empty strings and whitespace before querying the result.

Ignore cells containing only spaces

Spaces are text, so a cell containing " " is not null. Clean imported data with TRIM:

=ARRAYFORMULA(TRIM(A2:A))

For non-breaking spaces copied from web pages, replace CHAR(160) before trimming:

=ARRAYFORMULA(TRIM(SUBSTITUTE(A2:A,CHAR(160)," ")))

Use FILTER when the condition is simpler

FILTER can be clearer when you do not need the query language:

=FILTER(A2:C, A2:A<>"")

To exclude values containing only whitespace:

=FILTER(A2:C, LEN(TRIM(A2:A))>0)

Quick reference

RequirementQUERY condition
Blank column Awhere A is null
Non-blank column Awhere A is not null
Either A or B blankwhere A is null or B is null
Both A and B populatedwhere A is not null and B is not null

For checks outside QUERY, see how to ignore blank and empty cells in Google Sheets and ways to test for not-null values.