I'm trying to run a simple query to condense a list of information from a column (which contains a consistent data type), removing blanks. I have the following code:
=query({Z:Z},"select * WHERE NOT Z =''")
This produces the error: Unable to parse query string for Function QUERY parameter 2: NO_COLUMN: Z.
I've encountered similar issues with query elsewhere - for some reason not yet figured out by my brain, my columns somehow don't exist. I've tried using col26, col1, and everything between col1 and col30, to no avail. While I could workaround this particular simple situation with more of a filter() function, I'd like to better understand why my column's aren't computing. I'd appreciate any clarification on this.
Try this:
=query({Z:Z},"select * WHERE Col1 is not null")
When using curly brackets {} instead of normal ones () you can not use the column letters any more but the number of the column.
Example: When you have =query({D1:F10},"select * WHERE Col3 is not null") it means F is not null (D=Col1, E=Col2, F=Col3)
you can either use:
=QUERY({Z:Z}, "where Col1 !=''")
or:
=QUERY(Z:Z, "where Z !=''")
Related
This question already has answers here:
Query is ignoring string (non numeric) value
(2 answers)
Closed 5 months ago.
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:
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!)
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.
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))
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.
there are ways but "short-formula lovers" will hate it... for example:
=ARRAYFORMULA(IF(ISNUMBER(QUERY(TO_TEXT(Sheet1!A:Z), "where Col5 is not null", 0)*1),
IFERROR(1/(1/QUERY(TO_TEXT(Sheet1!A:Z), "where Col5 is not null", 0)*1)),
QUERY(TO_TEXT(Sheet1!A:Z), "where Col5 is not null", 0)))
or:
=ARRAYFORMULA(IF(QUERY(TO_TEXT(Sheet1!A:Z), "where Col5 is not null", 0)<>"",
IF(ISNUMBER(QUERY(TO_TEXT(Sheet1!A:Z), "where Col5 is not null", 0)*1),
QUERY(TO_TEXT(Sheet1!A:Z), "where Col5 is not null", 0)*1,
QUERY(TO_TEXT(Sheet1!A:Z), "where Col5 is not null", 0)), ))
if you need zeros
or try like this:
=FILTER(Sheet1!A:Z, TRIM(FLATTEN(QUERY(TRANSPOSE(Sheet1!A:Z),,9^9)))<>"")
=FILTER(your_formula, TRIM(FLATTEN(QUERY(TRANSPOSE(your_formula),,9^9)))<>"")
I am not sure why this functionality stopped working, but I am sure it has to do with inconsistent back end data or how the query condition "CONTAINS" needs to be changed. The IMPORTRANGE portion works just fine, but will not always pull data into the front end sheet. The query portion looks like this
SELECT Col3, Col2, Col1 WHERE Col2 CONTAINS "&'Job Number'!A1&" ORDER BY Col3 ASC,1
Column 2 contains job numbers that are xxxxx with another 3 digit code appended to end of it. It will only populate temporarily if I manually go into the sheet and edit the IMPORTRANGE range values. If I close the spreadsheet and open it again it will not populate. Does the data in Column 2 need to be a consistent datatype throughout the column or it will break the query?
Unfortunately we do not have a test sheet, so we can not know what the expected results would be.
Nevertheless, your formula syntax is not correct.
The correct syntax would be:
SELECT Col3, Col2, Col1 WHERE Col2 CONTAINS '"&"JOB"&A1&"' ORDER BY Col3 ASC,1
Please notice the syntax '"&"JOB"&A1&"'
(If you still have issues please share a test sheet and let us know.)
The full google spread sheet system is used for score keeping and is prone to delays when updating, however I have never run into an issue like this were the same basic function is returning two separate results. The problem is repeatable and occurs on more than one spreadsheet.
I have created a test sheet-
https://docs.google.com/spreadsheets/d/1arh0D9ch5MpQjRh_bHjLfLx5S7TAW8R_pgGLf5tovig/
with the code in question; Can anyone help please?
=QUERY(IMPORTRANGE("***","***"),"select Col1 where Col1 <>5 order by Col9 desc")
in your QUERY formula you are selecting cells that are numeric and comparing it to <>5 but take a notice that A2 is not numeric:
that is the reason why 2 2 is not included in your C column
also it looks like that your QUERY formula smashed first cells into one because you did not specify the 3td query parameter. try:
=QUERY(IMPORTRANGE("1pnowvo6YVj-DZAPCaKE2x9vSIbpAAmlwhRMO2OZNlrE","color!A84:M115"),
"select Col1 where Col1 <>5 order by Col9 desc", 0)
=QUERY({startingdates!D2:D, Cancelledtours!D2:D},"Select Col1 where not(Col1) matches Col2")
This seems to work for Column A but not column D. I'm at a dead-end. Can anyone help?
Sheet- https://docs.google.com/spreadsheets/d/1zEQmNs48CsaaioQOcwuK97kcmnDLDfX-57nuXFaLujc/edit?usp=sharing
You have to do a lookup on the starting date - the query as it stands only looks in the same row to see if there is a match:
=ArrayFormula(QUERY({StartingDates!D2:D, isnumber(vlookup(StartingDates!D2:D,CancelledTours!D2:D,1,false))},"Select Col1 where Col2=false"))
or slightly shorter using match:
=ArrayFormula(QUERY({StartingDates!D2:D, isnumber(match(StartingDates!D2:D,CancelledTours!D2:D,0))},"Select Col1 where Col2=false"))
Reversing the logic, this also works:
=ArrayFormula(QUERY({StartingDates!D2:D, isna(match(StartingDates!D2:D,CancelledTours!D2:D,0))},"Select Col1 where Col2=true"))
try:
=FILTER(startingdates!D2:D, NOT(COUNTIF(Cancelledtours!D2:D, startingdates!D2:D)))
Another problem with Google Spreadsheet API. I'm trying to use QUERY() function in order to get all customers from our database who are from Warsaw. Google API seems however to have a big problem with parsing my query. I've checked it few times and everything is OK. Tried semicolons, different apostrophes and column names—it still won't work. I type this code in the sheet cell:
=QUERY(IMPORTRANGE("0ArsOaWajjzv9dEdGTUZCWFc1NnFva05uWkxETVF6Q0E"; "Kuchnia polska!A3:G40"); "select B where E contains 'Warszawa'")
And get error like this:
Invalid query: Column [E] does not exist in table.
And I'm 110% sure that the column exists and the spreadsheet key is OK. ;)
If you are using the Query function with a direct reference to a rectangle of cells, then you use capital letters to refer to the columns. However, if you are using Query against the output of an array formula, such as the return from ImportRange, then you instead need to use Col1, Col2, ... to refer to the columns. So, your example query string would need to read:
"select Col2 where Col5 contains 'Warszawa'"
Working example:
=Query(ImportRange("0AtEH2Kw9zfIodEQ2dFNFam9sdEFEZlVnNEV3ZEZMZEE", "data!A:G"), "select Col3, count(Col4) group by Col3 order by count(Col4) desc label count(Col4) 'count'")
I've no idea why it doesn't just let you use names from a header row.
Alternatively you can try the FILTER function in this case and then you don't need to bother with SQL. :)
=FILTER(ImportRange("0ArsOaWajjzv9dEdGTUZCWFc1NnFva05uWkxETVF6Q0E"; "Kuchnia polska!B3:B40"); ImportRange("0ArsOaWajjzv9dEdGTUZCWFc1NnFva05uWkxETVF6Q0E"; "Kuchnia polska!e3:e40")="Warszava")
Although I admit that it's not so pretty because of the two importRange functions.
Hope it helped anyway.