Col BY causing parse error in Google sheets query - google-sheets

I'm trying to run the following Query in google sheets, but am receiving a parse error when I try to select the column BY. Without this column, it runs as expected.
Query below:
=QUERY('Applications received'!B:DL,"Select B,CT,CU,CV,CW,CX,BY where B is not null order by CX")
Any help is much appreciated!

BY column needs to be escaped with `:
=QUERY('Applications received'!B:DL,
"select B,CT,CU,CV,CW,CX,`BY`
where B is not null
order by CX")
https://developers.google.com/chart/interactive/docs/querylanguage#reserved-words

Related

Condition join in Google Sheets

(1) I am trying to TEXTJOIN email addresses in column F, if column B = a specific value. However, it is giving me all email addresses, regardless of column B value.
=TEXTJOIN(",",TRUE,IF(B$4:B$57="owner",F$4:F$57,""))
Sample table:
The result I am looking for is:
email1#testemail.com,email2#testemail.com
The result I am getting is:
email1#testemail.com,email2#testemail.com,email3#testemail.com
(2) If the formula is on a different sheet, I get an #VALUE! error.
=TEXTJOIN(",",TRUE,IF(sheet1!B4:B57="owner",sheet1!F4:F57,""))
(3) I am trying to have the results be de-duped or unique. Is it best just to add &UNIQUE=[range] within the array?
I'm sure I'm just missing some detail, but cannot figure it out. Any help appreciated!
You need an arrayformula() wrapper:
=arrayformula(TEXTJOIN(",",TRUE,IF(Sheet1!B4:B57="owner",Sheet1!F4:F57,"")))
In Excel 365 your formula works perfectly the way you wrote it .

IMPORTRANGE returning NO_COLUMN

I am using:
=query(importrange(SHEETID,"Orders!$A$2:$X"),"select Col1 where Col23=0")
in a Google Sheets and receiving the following error:
Unable to parse query string for Function QUERY parameter 2: NO_COLUMN: Col23"
I have authorized the IMPORTRANGE already and it will import that data correctly when used without the query.
Any ideas as to what is causing this error?
Remove the ) before the select like this:
=query(importrange("1_WqEDk9_XKakYVdzIm0eahWpBrY4-55ez4gauolMdAo","Sheet1!$A$2:$X","select Col1 where Col23=0")

#Value Error on Query - Google Spreadsheet

I'm trying to combine the data in two sheets into another sheet by using the below code:
=UNIQUE(ArrayFormula(query({filter('Sheet1'!A2:B,NOT(ISBLANK('Sheet1'!A2:A)));filter('Sheet2'!A2:B,NOT(ISBLANK('Sheet2'!A2:A)))},"order by Col1")))
It works perfect if both sheets have at least 1 row filled but if either of the tabs are empty, then I receive #Value.
How can I fix this code so that it still works if either of the tabs are empty?
Filter throws an error instead of returning no values, a property that is very annoying in this case.
Since you're already using the query command why don't you try this, either one or both ranges can be completely empty.
=UNIQUE(ArrayFormula(query(
{Sheet1!A2:B; Sheet2!A2:B},
"WHERE Col1 is not null order by Col1")))
Alternatively if Col1 contains always strings a shorthand is Col1 <> ''

Import selected rows with query on importrange

I'm trying to import select rows from a Google spreadsheet based on the value of a single cell in each row.
As such, I'm using the following:
=query(IMPORTRANGE("KEY","Form Responses 1!A:L"), "select * where J contains 'DENIED' ")
Wherein the KEY is an actual spreadsheet Key. I tested the importrange part, that is without the query, to confirm it works. It does. Furthermore, within the Google Spreadsheet itself I can query the sheet and get it to work.
The error I receive is:
#VALUE Error Unable to parse query string for query parameter 2: NO_COLUMN_J
(There is a column J.)
When you use an importrange as a dataset, you need to refer to the columns by number rather than letter. The formula also works without 'select *'. Try:
=query(IMPORTRANGE("KEY","Form Responses 1!A:L"),"where Col10 contains 'DENIED'")

How do I do a date-based query in new Google Spreadsheets?

I am using the new Google Spreadsheets that was rolled out a couple of weeks back. I'm using a following query to pull data out of another spreadsheet:
=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheet/ccc?key=blablathisisanexample", "samplesheet!A:D"), "select SUM(Col4) where ( Col1 >= date '2012-1-1' ) ")
The query works perfectly well if I remove the bit 'where ( Col1 >= date '2012-1-1' )'. It will pull data and sum it correctly.
But what's wrong with my where-col1-date filter thingy? It's written the way it was in previous version of Google Spreadsheet, and it gives no error messages. It just returns a header and no result, as if it didn't find a single date. The dates in the data file are in column 1, written in format 4/7/2014, for example. This used to work in the previous version and I'm at a loss now.
I have several suggestions here. But first: Let's copy the "2012-1-1" value to a particular cell, say F5, and write it with the exact same date format az in the original spreadsheet: 1/1/2012.
Use FILTER function:
=SUM(FILTER(IMPORTRANGE("https://docs.google.com/spreadsheet/ccc?key=blablathisisanexample", "samplesheet!D:D"), IMPORTRANGE("https://docs.google.com/spreadsheet/ccc?key=blablathisisanexample", "samplesheet!A:A")>=F5))
I admit that it's not that pretty because of the two ImportRange functions, but it works for sure, I tried it.
If you insist on using QUERY then try to replace the where condition as follows:
"select SUM(Col4) where ( Col1 >= " & F5 & ")"
I haven't tried this one, but the first one (with FILTER) should work.

Resources