Trying to query select cells based on data in another cell - google-sheets

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)

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.

Using Indirect function as a dynamic input inside the query function in google sheet

I have a google sheet (Final Calculation) where I am trying to get sum of all values in Column G (in Data tab) against a set of values in Column B, L and D (in Data tab). However, condition for values in Column D is dynamic and would likely change every month. I have created a tab Advertiser List where the condition for filter in Column D gets updated. How, do I use this condition in Query function used in C5 cell in Final Calculation tab?
I tried referencing the condition in Advertiser List sheet using indirect but I am getting an error. I have also added a hard coded formula is other cells in Final Calculation tab to show what am I trying to achieve.
Below is the formula that I have written and is showing an error:
=iferror(QUERY(Data!$A:$L, "Select Sum(G) where B = '"&$B5&"' and L = '"&C$3&"' and indirect('"Advertiser List"'&'"!"'&'"D2"') label sum(G)'' "),0)
Here is the link of the Google Sheet (Link)
You don't need INDIRECT to get a text value from another tab:
=QUERY(Data!$A:$L, "Select Sum(G) where B = '"&$B5&"' and L = '"&C$3&"' and (" & 'Advertiser List'!D1 & ") label sum(G)'' ")
When in doubt, try to build the "select ... " string in a separate cell until you see the expected result. Then wrap it with query and check again. Adding IFERROR should always be your last step, because you will want to see the errors that your query is throwing.

Google Sheets: Textjoin from another sheet not working

Working with the Base and Data tabs from this sheet: https://docs.google.com/spreadsheets/d/1OsSWQ_48VrcTU3pXGeJ_1syluKPVeVRune39UA9I3x4/edit?usp=sharing
Expected result is textjoin of all colors matching SKU separated by comma in column C on Base tab.
Expected result shows in Column D, done manually.
All formulas i've tried either put everything in one cell (C2), gives an N/A error(C4), just pulls the first result (C5) or it is just completely blank.
Please help? If you cannot, then thank you for reading anyway.
I did it on a new Sheet on the Spreadsheet that i took the liberty to create (hope it's ok)
For getting the colors I used QUERY: so it came out as QUERY(Data!B:G,"select G where B = '"&A2&"'". After that I just fed that to your JOINTEXT formula

GoogleSheets Query formula skipping a cell

I've got a sheet where I'm using a Query formula to create a small "reporting section"
It's working fine except for the fact that it's missing data for the top right cell.
I've put a simplified screenshot below
So the query is basically getting data from the bigger table on the left where Column B matches the name in cell G2.
It's working fine, in that it is returning the data when I change the employee name, but for some reason, it skips the top right cell (highlighted in red)
It should say Figures there, but for some reason it's empty and I can't figure out why.
Even if I take out the where clause in my query formula. I get all the data, and the Figures value is in the top row, but further down it's missing, and I have no idea why.
The query() function only supports one data type per column. The subheadings are text, and will be returned as null because they are in a numeric column.
To make it work, put these values in cells B1:D1:
Employee Project Name Figures
The choose View > Freeze > 1 row and delete the rows in the data table where column C is Project Name, and modify the formula like this:
=query(B1:D, "where B = '" & G2 & "' ", 1)

Trying to filter a query using data validation drop down - numerical options work, but not a combination of numbers/letters [duplicate]

This question already has answers here:
Query is ignoring string (non numeric) value
(2 answers)
Closed 5 months ago.
Here is a copy of my sheet https://docs.google.com/spreadsheets/d/1b7ofD9f02yKiIvGYfCBi_GdhkRtgTAoY2NpftJmZaDQ/edit?usp=sharing
So my query is on the front tab 'Overall' in D1
=query(Data!A1:G,"SELECT * WHERE 1=1 "&IF(A2="All Raids",""," AND A contains "&A2&" ") &IF(B2="All Classes",""," AND LOWER(B) = LOWER('"&B2&"') "),1)
On the datasheet, I have people listen in raids 1,2 and 3.. and it works fine. However, if I were to change a value to something like BWL1 or BWL2, it will not display.
I got this code from a youtube tutorial, so I don't understand it 100%, but basically the "a2=all raids","" part is just to remove any filters, then the remaining is filtered by my drop-down menus, &A2& and &B2&.
Any ideas?
I've tried using A CONTAINS "&A2" instead of A = "&A2&", I just cant figure out a workaround to where any value (numberical+lettered) listed in my Datasheet column A works.
Thank you in advance for your time, I hope this makes sense :)
That's a known issue with query() function: query() has trouble with mixed datatypes (numeric and text in column A). To avoid this you can convert column A to text. See if this formula works
=query({ArrayFormula(to_text(Data!A1:A)), Data!B1:G},"SELECT * WHERE 1=1 "&IF(A2="All Raids","", " AND Col1 contains '"&A2&"'") &IF(B2="All Classes",""," AND LOWER(Col2) = LOWER('"&B2&"') "),1)
Note that, because of the use of 'contains' when '1' is selected in A2, it will also show rows containing BWL1. If you don't want that, change 'contains' to '='.

Resources