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)
Related
=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
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:
I'm trying trying to build out a stock financial analysis spreadsheet this is the example sheet. I have a financials tab where I import the balance sheet, income statement, and the cash flow statement by csv. In another tab I wrote queries that'll populate the financial statements based off of whatever ticker I put into the cell
=QUERY(Financials!B4:M, "SELECT * WHERE B = """&B2&""", ")
=QUERY(Financials!Q4:AB, "SELECT * WHERE Q = """&B2&""", ")
=QUERY(Financials!AH4:AR, "SELECT * WHERE AH = """&B2&""", ")
In the Example sheet I put a blue border where I placed those query functions. The problem I'm having is I keep getting a parse error for all 3.
Try this:
=QUERY({Financials!B4:M}, "SELECT * WHERE Col1 = '"&B2&"'")
=QUERY({Financials!Q4:AB}, "SELECT * WHERE Col1 = '"&B2&"'")
=QUERY({Financials!AF4:AR}, "SELECT * WHERE Col1 = '"&B2&"'")
Output:
Reference:
QUERY
As experienced I am in sheets concatenating strings often gets the best of me with the single and double quotes. I suggest you break the formula down. So, in another cell, get the SELECT clause string working then add back to the QUERY() function.
="SELECT * WHERE Col1 = '"&B2&"'"
This is sometimes referred to as the onion approach. If you get an error on the string formula you can break it down further until your identify where the problem is. In this case it is where you are referencing cells.
Another approach is to start with a hard coded formula then substitute the cell references:
=QUERY(Financials!B4:M, "SELECT * WHERE B = """&B2&""", ")
Becomes:
=QUERY(Financials!B4:M, "SELECT * WHERE B = 'AAPL', 1)
Then substitute 'AAPL' with a cell reference using the concatenate operator (&) and single quotes (since the entire string is using double quotes.
=QUERY(Financials!B4:M, "SELECT * WHERE B = '"&B2&"'", 1)
There is also a CONCATENATE() function which I sometimes use as well
=QUERY(Financials!B4:M, CONCATENATE("SELECT * WHERE B = '",B2,"'"), 1)
Some feel this is easier to follow without all the ampersand operators
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 & "'")
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.