Google Sheets Query ImportRange where Col = Column(NamedRange) - google-sheets

=QUERY( IMPORTRANGE( "https://URL", "Name Of Sheet!1:999" ), "SELECT * WHERE Col" & COLUMN(namedRange) & "'is not null",0 )
This spits out the error of:
Unable to parse query string for Function QUERY parameter 2: PARSE_ERROR: Encountered " <ID> "Col1 "" at line 1, column 16. Was expecting one of: "(" ... "(" ...
I know part of the solution is working with the "&" symbol to join certain blocks of quotes. The biggest challenge is putting the right quotation marks in the right spot.

try:
=QUERY({IMPORTRANGE("id", "Name Of Sheet!1:999")},
"where Col"&COLUMN(namedRange)&" is not null", 0)
select * is not needed if you want all columns
https://URL you dont need it either, just put there ID number of the sheet

Assuming the named range is called TEST
"select Col" & COLUMN(TEST) & " where Col" & COLUMN(TEST) & " is not null "
or
"select * where Col" & COLUMN(TEST) & " is not null "
you have omitted WHERE syntax

Related

Google Query Select All or Specific Text via Cell Reference

The formula below is working to select All, but throws any error when I go to search specific text. ON a seperate tab, I created another query that works with the specific text.
Cell reference A4 is the drop down list with All, Status 1, and Status 2 that I would like to be able to select data from.
=Query({QUERY(importrange("xxxxx", "'"&A1&"'!A3:Q150"), "SELECT * WHERE Col6 >= "&A3&" AND Col6 <= "&B3&"", 0)}, "SELECT Col1, Col2, Col3, Col4" & IF(A4= "All",, "Where Col4 = '"&A4&"'"),0)
I have the Status 1 and Status 2 working on a seperate query, and the All working on current query, trying to make them work on one sheet. Currently only All works. When status 1 or status 2 are selected it throws this error.
Unable to parse query string for Function QUERY parameter 2: PARSE_ERROR: Encountered " "Col4 "" at line 1, column 36. Was expecting one of: "where" ... "group" ... "pivot" ... "order" ... "skipping" ... "limit" ... "offset" ... "label" ... "format" ... "options" ... "," ... "" ... "+" ... "-" ... "/" ... "%" ... "" ... "/" ... "%" ... "+" ... "-" ...
Try to add a space before where or after the first Col4
=Query({QUERY(importrange("xxxxx", "'"&A1&"'!A3:Q150"),
"SELECT * WHERE Col6 >= "&A3&" AND Col6 <= "&B3&"",0)},
"SELECT Col1, Col2, Col3, Col4" & IF(A4= "All",, " Where Col4 = '"&A4&"'"),0)
try:
=QUERY(QUERY(IMPORTRANGE("xxxxx", A1&"!A3:Q150"),
"where Col6 >= "&A3&"
and Col6 <= "&B3, ),
"select Col1,Col2,Col3,Col4"&
IF(A4="All",," where Col4 = '"&A4&"'"), )
you can drop all of these:
array brackets {} no need coz inner QUERY is not a range
single quotes within IMPORTRANGE coz it applies the same rules as with INDIRECT
zero 0 as the third QUERY argument coz it can be just omitted
select * if you want all columns then just skip the whole select argument
ending QUERY with &"" after B3 coz its totally redundant

search for a specific Column and then lookup the value of the matching row based off a name

I am trying to get a google sheet to search for a specific cell in a table. The headers change so it might be A6 one week and then A9 the other and so on.
Once it's found that row, I want it to search and pull all of that departments names and data for the column its matched with.
I am 23 sheets in and my heads hit a brick wall and I just can figure it out.
You can try:
=QUERY({A:B,INDEX(A:G,0,MATCH(D25,1:1,0))},"SELECT * WHERE Col2='" & LOWER(F25) & "'")
Note - you should remove unnecessary spaces. In sample data, they were in cells C1 and D25.
Try this:
=QUERY(
FILTER(
IFS(
TRIM(1:20) = "", 0,
ISNUMBER(1:20), 1:20,
True, LOWER(TRIM(1:20))
),
1:1 <> ""
),
"SELECT Col1, Col2, Col" & MATCH(TRIM(D25), ARRAYFORMULA(TRIM(1:1)),) & "
WHERE Col2 = '" & LOWER(F25) & "'",
1
)
You can use a combination of CHAR(MATCH...)) and Query formula to get this
=QUERY('Sheet Name'!A1:G20,"SELECT A, B, "&CHAR(MATCH("Log 4",'Sheet Name'!A1:G1)+64)&" WHERE B='w'")
Above formula only works till column Z, but thanks to Kishkin's comment below, you can use it beyond Z like this:
=QUERY('Sheet Name'!A1:G20,"SELECT A, B, `" & =REGEXEXTRACT(ADDRESS(1, MATCH("Log 4",'Sheet Name'!A1:G1), 4), "\D+") & "` WHERE B='w'")
You use SUBSTITUTE instead of REGEXTRACT too. You can refer to this Question.
the CHAR(MATCH...)) gets the column name of the desired Log
you can then use the column name to include that column in Query select statement
In the MATCH formula, you can also dynamically Match for a cell reference instead of specifying "Log 4" manually
Note: This is basically splitting the Query formula and concatenating it with another formula. So the &, ' and " symbols are really important
Sample Screenshot:

QUERY Function Question Regarding WHERE clause

I have a query where I am trying to match the range value with the value that is in the first column (A) of the current row:
=QUERY(IMPORTRANGE("https://URL.com", Spreadsheet!A:Z), "SELECT COl4 WHERE Col1 = "' & CONCATENATE('A', ROW()) & '")
So essentially, I am trying to select the value of col4 if col1 matches the value of "A235" or A + whatever the current row is.
However the Concatenate part doesn't seem to be working (Formula parse error) and if someone could point me in the right direction, it will be awesome.
Thanks!
Repeating a working solution from my comment.
Try this:
=QUERY(IMPORTRANGE("https://URL.com", Spreadsheet!A:Z), "SELECT COl4 WHERE Col1 = '" & A:A & "'")

How to refer to a cell value when using a query

I am trying to populate columns C,D,E,L,K,M,N on a Google Sheets spreadsheet..
Below is my code but it returned a VALUE error when I ran it. Could someone please advice?
=QUERY(QUERY('BI_Keywords Raw Data'!$A:$C, "Select * WHERE B = """&B2&""" " ), "SELECT * OFFSET 1", 0)
Thanks a lot!
You have a mistake within the query syntax trying to connect it with the value in cell C2.
To include a cell value in a query you need to use a combination of singe and double quotes like
'"&A8&"'
Single quote ' double quote " ampersand & cell A8 ampersand &double quote " single quote '
Thus, your corrected query would be
=QUERY(QUERY('BI_Keywords Raw Data'!$A:$C, "Select * WHERE B = ' "&B2&" ' " ), "SELECT * OFFSET 1", 0)

Concatenate or insert a number into a QUERY() string in Google Sheets

I am trying to use QUERY() to call a column of data from one sheet to another based on the contents of other columns. The code below works just fine.
=query(Data!$A1:$Y15), "select Col7 where Col1 starts with """&E$2&""" ")
However, I want to copy this data and have Col7 change to match the row of the cell that the formula is in + 1. It should be something like this (the formula is in cell F6):
=query(Data!$A1:$Y15), "select Col"""Row(F6) + 1""" where Col1 starts with """&E$2&""" ")
How can I concatenate or insert a number into a query string? I do need to use query due to some other constraints I simplified out of this example.
Just use & for concatenation, the way you did around E$2.
"select Col" & Row(F6) + 1 & " where Col1 starts with """ & E$2 & """ "
I would also use single quotes around the string from E$2, because they don't need to be escaped by doubling:
"select Col" & Row(F6) + 1 & " where Col1 starts with '" & E$2 & "'"
Also, Row(F6) could be simply Row() which returns the row of the current cell.

Resources