Search code examples
google-sheetsgoogle-sheets-formulagoogle-sheets-querygoogle-query-language

Search with query formula where cells are not nothing


I have range of cells and want to search with query formula where cells are not nothing.

    A   B   C   D
1   a   11  44  qw
2   b   12  r   
3   c   13  44  444
4   NOT         
5   f   15  55  88
6   NOT         
7   h   17  gh  ee

Cells in C maybe any number, maybe any word, maybe any nothing.

I want to select everything A where C has nothing. Result must be:

a
b
c
f
h

When try all the querys formula:

=QUERY(A1:D7,"select A where not C<>'' ")
=QUERY(A1:D7,"select A where not C!='' ")
=QUERY(A1:D7,"select A where not C is null")
=QUERY(A1:D7,"select A where C !='' or not C is null")

Nothing give correct result. Looked everywhere.

What can I do?


Solution

  • Google QUERY function does not work here as "expected" because of mixed data types in column C. If we apply the formula =QUERY(A1:C7;"select A where C is not null";-1) it will return only "a, c and f". The image below shows this result in column G, where G1 contains the above formula.

    Formulas and testing

    We should check data types more carefully, but it is difficult to do inside QUERY function. So I suggest to add one more column (E in our case) and fill it with "=TYPE(C1)" and similar functions. Having data types column, we can modify QUERY expression to take them into account. Final result is shown in column H.

    Please check this approach again, if you are going to use other data types in column C.