Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query formula ignores string values [duplicate]

I have a table that is a result of a few smaller tables merged together. It's a result of searching a few sheets for rows that meet filtering criteria.

I wanted to remove empty rows using QUERY formula but it works in a strange way!

Normally

=QUERY(A1:Z,"Select *",0) 

should return a full table. But not in this case.

What I actually try to do is to remove empty rows. I tried:

 =QUERY({A1:Z},"Select * where Col5 is not null",0)

as column E is empty only when whole row is empty. But it does not work. It seems to ignore string values and sees only numbers.

Here is dummy table. https://docs.google.com/spreadsheets/d/12QmFW9vlx4ToHsQYGmkXK4aLD2jlI30FV1wYgxa0V8c/copy

It looks like this: enter image description here

When I apply Query that should cut empty rows, my result table looks like this: It seems to cut all the rows without number value in Column A (strange!)

enter image description here

Note: Table is generated by a very long formula that searches multiple sheets. Whenever result is not found in one of sheets, formula returns empty row. So I need a solution to wrap around existing formula. Normally QUERY is a way to go, but not this time. I know that I can make additional step. Make one more sheet and use Filter:

=filter(Sheet1!A1:Z,Sheet1!E:E<>"")

Anyway this solution adds bulk to my spreadsheet.

like image 343
Krzysztof Dołęgowski Avatar asked Oct 16 '25 11:10

Krzysztof Dołęgowski


2 Answers

If you convert Col E to text (TO_TEXT), you can run the query without worrying about mixed data:

=index(query({Sheet1!A:D,to_text(Sheet1!E:E),Sheet1!F:Z}, "select * where Col5 is not null ",0))
like image 132
Aresvik Avatar answered Oct 18 '25 06:10

Aresvik


QUERY only returns the predominant data type per column. Your E column has mixed data types (strings and numbers, with numbers being predominant), so anything that is not a number will be a null — and thus ruled out by the QUERY.

As for how to solve it, that would be difficult to impossible to do given your sample spreadsheet only, since we can't see the actual formula that generates the initial output shown in sample Sheet1.

like image 39
Erik Tyler Avatar answered Oct 18 '25 05:10

Erik Tyler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!