QUERY syntax for using a 'cell reference' after the 'where' - google-sheets

I'm trying to use submitted Google Form data in one spreadsheet to locate and retrieve data from another spreadsheet (tab in same document). The Google Spreadsheet file is here.
The =QUERY statement I'm trying to use is below
=QUERY(sheet2!A1:K; "Select B, C where A =" & B1 ; 0)
It works if I remove the 'cell reference' from where A =" & B1 ; 0) and I replace it with a 'static value' like where A contains '123456' ")
Any suggestions on 'how' to get the =QUERY to work using a 'cell referenced' value. The heading for the column being referenced is TEXT but the value of all rows below the heading is a NUMBER
Thank you in advance,
Todd

I know this is old but I had the same issue and thought my solution might help others. Adding single brackets round the cell reference worked for me.
=Query(sheet2!A1:K, "select B, C where A ='"&B1&"'")

Related

Google Sheets Query with Variables in the data section

I am trying to create a health related spreadsheet that has a lot of data - a lot of which isn't relevant to this question so I've simplified it. There is a column for each type of pain where you write on a scale of 0-10 how intense your pain was, and another column for any relevant notes. The data is broken up into named ranges to make it easier to display on different tabs (HeadData = Head Pain, ChestData = Chest Pain, etc. - 15 named ranges in total.)
One of the tabs I'm working on has a table where you are viewing only the specific named range, in this case HeadData.
=query({HeadData}, " Select * where Col1 is not null ",1)
This works perfectly, but I want to replace {HeadData} with a reference cell to a drop menu so you can select the specific pain area column you want to be displayed.
If I put the reference cell in G1 with a drop down list of the named ranges and select ChestData and try to do
=query({&G1&}, " Select * where Col1 is not null ",1)
It is only picking up G1 (ChestData) as a string and not the actual named range.
So my question is, is there a way to make a drop menu containing named ranges that turn into actual sets of data and not strings when placed in the data section of the query?
Here is my spreadsheet, any help is appreciated. Thanks!
https://docs.google.com/spreadsheets/d/1CcuSV2bbfxsUPPkmj-fru2yYYmmtpXk9LKEF85sxVUw/edit?usp=sharing
You can use INDIRECT for this.
INDIRECT
Returns a cell reference specified by a string.
Change your formula to
=query({INDIRECT(G1)}, " Select * where Col1 is not null ",1)
The INDIRECT function will convert the string in G1 to a cell reference and then the rest of your formula will query the relevant named range.

Trying to query select cells based on data in another cell

Not really sure what’s wrong with my function but I’ve tried so many different variations to make it work and I keep getting an #ERROR! with a “formula parse error” pop-up
What I’m trying to do is populate a sheet from data in another sheet. I only want specific cells in Column C from the other sheet to populate based on the text contained in Column D cells (on the ‘other’ sheet)
So the fxn i have going now is:
=QUERY({‘[insert other sheet name]’!C3:D}; “select C where D=“‘[insert desired text]’;0)
I’ve tried the fxn without the ‘C where D ...’ part and it worked fine populating all of the data without selecting any specific cells so I’m sure that’s where the problem is.
I’ve also tried ”select C where D contains ‘[insert desired text]’” or ”select C where D = ‘[insert desired text]’” and a number of other variations with no luck ... anyone have any ideas?
Don't use these ” , ‘ or ’.
Instead do use these " or '.
Try this:
=QUERY('insert other sheet name'!C3:D; "select C where D contains 'insert desired text' ";0)
or this:
=QUERY('insert other sheet name'!C3:D; "select C where D = 'insert desired text' ";0)

IMPORTRANGE: value missing?

I have been working on this issue for a few weeks now and can't seem to find a solution. I used this answer (IMPORTRANGE with CONDITIONS) to get as far as I could, but I keep getting a value error.
This is the sheet I'm working with.
My goal is to use the first tab in the sheet (All Games) to enter all the games that I come across to create a compendium. But, then I want it to automatically populate the other tabs based on certain criteria (what type of game, skills learned, etc.)
On the Warm-Ups tab you'll see the formulas I have tried. A1 is the most recent.
Here is the formula I tried:
=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1F64PMg_iFu-DaJAUaE4BkpqF4zoteknp56VfwAUe8ag/edit#gid=1359689553", "All Games!A1:A1300"),"SELECT Col1 WHERE (Col2 = 'w') ")
I am getting a value error:
Unable to parse query string for Function QUERY parameter 2: NO_COLUMN: Col2
you are trying to reference Col2 but you selected range A1:A1300 which is just 1 column. therefore try:
=QUERY(IMPORTRANGE("1F64PMg_iFu-DaJAUaE4BkpqF4zoteknp56VfwAUe8ag", "All Games!A1:B1300"),
"SELECT Col1 WHERE (Col2 = 'w') ")
from the brief look on your sheet, you may want use matches or contains instead of = in your QUERY
You are only importing (part of) ColumnA - so no wonder Google can't find a second column :)

Conditional formatting with QUERY result in Google Spreadsheet

I have a spreadsheet with 1 sheet of software version an another sheet of installation records. I want to do a conditional formatting that compares the version of in installation (on column F) to its know latest version number on another sheet ('Software Versions').
Current Solution
I came up with this formular initially:
=AND(F2<>"", F2=G2)
It works. But I need to maintain a column of QUERY results on G2:
=QUERY('Software Versions'!$A$1:$B$8, "Select B where A='" &D4& "' LIMIT 1")
Problem
Now I want to remove the G2 row altogether. I came up with this combined query:
=AND(F2<>"", F2=QUERY('Software Versions'!$A$1:$B$8, "Select B where A='" &D4& "' LIMIT 1"))
But I cannot save it because it is an "Invalid Formula":
Any way to actually do it?
Try use this formula:
=AND(F2<>"", F2=IFERROR(QUERY(INDIRECT("'Software Versions'!$A$1:$B$8"),
"Select B where A='" &D4& "' LIMIT 1 label B ''"),""))
I was able to make conditional formatting with this formula.
Improvements
Use indirect to address another sheet
Use label B '' to prevent header appear as query result
Use iferror(..., "") to be sure no error occurs when no data is found with query
I'm used to the good old VLOOKUP function for my conditional formattings.
The syntax is VLOOKUP(valueOrCell, sourceRange, index, FALSE)
So if the value from first parameter valueOrCell, exists in the sourceRange, return the value at index. FALSE is to have the exact match.
In my example I'm using only a single worksheet, but if you set the sourceRange to different worksheet it works as well.

Formula Parse Error when using Join function

I'm trying to use the JOIN function to concatenate all the values of a column using a space and the at-sign (" #") as a delimiter. I'm receiving a Formula Parse Error when using the following text:
=JOIN(" #",!A2:A)
The referenced column is completely empty right now. Is that what's causing it not to function? If so, is there another way I can concatenate a row with a delimiter that will function even when some of the referenced cells are empty?
If it helps here is a link to the spreadsheet. The "Buyers Pinglist" is the one I need help with.
Thanks in advance!
You could wrap the formula in an IFERROR if you don't want the #N/A to show:
= IFERROR(JOIN( " #" ," ", FILTER(B3:B, NOT(B3:B = "") )))
The formula seems to work as soon as a value is added to the 'Buyers' tab - the issue is that when the column B is completely empty then there is no data returned by the FILTER and hence nothing for the formula to JOIN

Resources