I want to run a query based off of several user inputs but I would like for the query to still run even if one of the inputs is left blank.
For example, my current query will run if the fields "Square Footage", "Property Type" and "ARV" are filled in but if I leave one or more blank it will not run. I would like for me to be able to leave them blank and it would then that field would essentially be a wildcard and the query wouldn't take that field into consideration.
My current query code is: =QUERY(Test!A2:L1000, "select * where L contains '"& E2& "' and K contains '"& D2& "' and D contains '"& B2& "' ")
enter image description here
It is extremely difficult to write formulas when we don't have access to your sheet and data as described in forum rules. A picture is not much help, which is why the rules ask that people share a link to their sheet (or a copy of it) with share permission set to "Anyone with the link can edit."
That said, you can try this:
=QUERY(Test!A2:L1000, "select * where A Is Not Null"&IF(E2="",""," and L contains '"&E2&"'")&IF(D2="",""," and K contains '"&D2&"'")&IF(B2="",""," and D contains '"&B2&"'"))
If that doesn't work, please do share a link to your sheet or a copy of your sheet with permission set as described above.
Related
This is what I have so far, I am getting stuck where I would usually do the IN syntax also AND with SQL WHERE
See the images for explanation of the following:
An example data for A in sheet1:
cell1 = [A,B,C]
cell2 = [A,B]
Cell3 = [A]
Sheet: OverallGroups
Team
Projects
Bring
A,B,C
Frying
Oil, flour, sugar, chicken
A, B
Baking
Oil, flour, sugar
A
Crafting
Paper
Sheet: Jobs
Team
Projects
Due
Bring (Return Query here)
B
Frying
1/2/14
C
Frying
1/3/14
A
Frying
1/4/14
B
Baking
1/5/14
B
Baking
1/6/14
A
Crafting
1/7/14
A
Crafting
1/8/14
The sheet2 "jobs" has in column A just one letter out of the potential lists in cell1,2,3..., delimited by comma.
The format allowed the most condensed view of the jobs on the first sheet, then the jobs sheet expands them for specific when and where per project.
I know that is isn't conventional to have multivalued fields, but it was necessary to summarize the data view rather than have a flooded screen of replicates to manage missing elements in this school project.
An example problem:
I want to find WHERE TEAM A IN [A,B,C] exists in one instance and the related project from B in the query to explain what to bring to class. The selection returns one block of text content from C. And the condition that project matches the with the team letter.
=QUERY({OverallGroups'!A:C; Jobs'!A}, "Select C WHERE A matches '" & OverallGroups'!A:A & '" AND A matches " & Jobs'!A & "'")
I tried using
&TEXTJOIN()
but this works for one to one cells, and won't parse the inner list by the comma.
------------- Part 2 need to copy the links by query 11/28/22--------
I have a query in Google Sheets which will search a template of materials to bring for another expanded sheet which has unique answers, but I need the links to appear as a result from this query
The difficulty is in being able to import multiple links per cell and groups to sort bringing materials for by the query.
The best snippet of code for this I have gets an error from another post: =BYROW(A2:A,LAMBDA(each,filter(OverallGroups!C:C,ARRAYFORMULA(REGEXMATCH(OverallGroups!A:A,"(?i)"&each)),ARRAYFORMULA(REGEXMATCH(OverallGroups!C:C,"(?i)"&OFFSET(each,0,1))))))
"No matches are found in FILTER evaluation: #N/A"
This script on Google Sheets will provide the working data without hyperlinking...
=query('OverallGroups'!A:C;"Select C where A contains '"&A2&"' and B contains '"&B2&"'")
Please reference the data from these two tables to get the answer in the second table "what to bring" so that it references the links.
I'm glad it was useful! Here you have a multirow option:
=byrow(A2:A;lambda(each;if(each="";"";query('OverallGroups'!A:C;"Select C where A contains '"&each&"' and B contains '"&offset(each;0;1)&"'"))))
The answer is from Martín on this post (solved part I):
"Something like: =query('OverallGroups'!A:C;"Select C where A contains '"&A2&"' and B contains '"&B2&"'") should do the job for one row, Let me know"
I'm trying to use Google Sheets to manage a database. I've figured out how to use the query function to do a simple search, but I'd like to know if an advanced search is possible. Here's what I mean:
Example I made (refer to the second sheet)
Each row has a number of attributes, and the search sheet has a number of fields that can be entered. I'd like to be able to search for one without having to keep the other fields filled in as well, but I'm not sure how to mess around with the query function to get what I need.
Any help would be very much appreciated. Thank you!
Where must only appear at the beginning of the filtering, not before every conditional.
This can be done with FILTER and some if statements or keep the query and adjust it similarly like this:
= IFERROR(
query(
Database!B3:G13,
"select B,C,D,E,F,G
where " &
IF(LEN($C$4), "lower(C) contains lower('"&$C$4&"')", "1=1") & " and " &
IF(LEN($E$4), "lower(D) contains lower('"&$E$4&"')", "1=1") & " and " &
IF(LEN($G$4), "lower(E) contains lower('"&$G$4&"')", "1=1") & " and " &
IF(LEN($I$4), "lower(F) contains lower('"&$I$4&"')", "1=1") & " and " &
IF(LEN($K$4), "lower(G) contains lower('"&$K$4&"')", "1=1")),
"No Results")
It essentially checks if the filter is specified and if not puts 1=1 (TRUE) as a placeholder.
https://docs.google.com/spreadsheets/d/1ZupYqXhA-_ZSfuOUN70YuQnC9DUw7PUlrzv117knJ-I
That's a link to the file in which it is not working! If you open it, go to sheet named "My query stinks".
The sheet called deposits has data like this in columns A (date), B (description), and C (amount):
6/29/2016 Deposit 480
6/24/2016 Deposit 359.61
8/8/2016 Deposit 11.11
The sheet "My Query Stinks" has data in columns A (check number), B (empty) and C (amount):
1000000044 480
1000000045 359.61
201631212301237 11.11
In Column B on My Query Stinks, I want to enter a query. Here's what I'm trying: =query(Deposits!A2:C,"select A where C ='"& C4 &"'") For some reason, it returns #N/A Error Query completed with an empty output. I want it to find that 11.11 (the value in C4) matches 11.11 over on Deposits and return the date.
EDIT 1/15/2020: Updated the link to the Google sheets file.
I think you've ended up with too many quotes in your formula. The following simplified version seems to work.
=query(Deposits!A2:C,"select A where C = "&C4)
Because of an extra set of quotes in the formula, I believe your original version ends up treating C4 as a text value instead of a cell address.
Additionally, it looks like that element opens with '" and then closes with "'" - so it's not balanced. I've had problems with auto-quoting like this in similar scenarios, especially on editing.
I'm trying to make a database of students using Google Sheets. It contains info about students, groups and orders; orders can change students membership in groups (taken in a group, moved up to a new group, graduated, on leave, sent down). Here are sample database sheets and here is a detailed description of my DB structure (the sheet report_Groups is slightly changed, its previous variant, described on the link, is now named old_report_Groups).
I need a query that would select a list of present members of given group on the given date. That means that for each student I have to select
the name, the latter status before given date and corresponding group. And from this result select student names, where statuses are "Taken in" or "Moved Up" and group is the same as given one.
The problem is to select the latter status. It should be MAX(status), whose "since" date ≤ given date, but there's a well-known problem of selecting more than one field together with aggregate function. Here is a question which is very close to, but query from its "best" answer gives me error "QUERY:NO_COLUMN". I've even copied the sheet Raw from there and tried to perform proposed query (with the onliest modification — replacing commas with semicolons according to my locale restrictions) on the data it was reported to work on — same error (check Raw and report_Raw sheets in my DB). Other variant (via MMULT and TRANSPOSE) works, but it's perfomance is very poor.
What can you suggest me? Thanks in advance.
Update: I've found the solution with an issue (described in my answer).
To solve the issue I need to know an answer for a different question.
Here's the solution (with an issue described below).
A. Orders_Students is filtered for selecting rows, having "since" cell value ≤ given date (report_Groups!A2):
=QUERY(Orders_Students!B:E;"select E, B, C, D where E <= date '" & TEXT(report_Groups!A2;"yyyy-MM-dd") & "'";1)
This interim result is stored at the inner_report_Groups tab (it will be referenced few times in the next query).
B. inner_report_Groups is filtered for selecting MAX("since") values and corresponding row cell values for each student:
ARRAYFORMULA(VLOOKUP(QUERY({ROW(inner_report_Groups!A$2:A)\SORT(inner_report_Groups!A$2:D)};"select max(Col1) group by Col3 label max(Col1)''";0);{ROW(inner_report_Groups!A$2:A)\SORT(inner_report_Groups!A$2:D)};{3\4\5};0)
The formula above is used as inner query in report_Groups!D2 (also in D3, D4—with appropriate indeces).
C. The second query result is filtered to get students whose status is either "Taken in" or "Moved Up" and corresponding group is equal to the given group (report_Groups!B2 (also in B3, B4—with appropriate indeces)):
=TRANSPOSE(IFERROR(QUERY(<here is the formula from step B>);"select Col1 where Col3 = '" & B2 & "' and (Col2='Taken in' or Col2='Moved Up')";0)))
The formula above is used as outer query in report_Groups!D2 (also in D3, D4—with appropriate indeces). IFERROR is intended to display nothing if query result is #N/A.
That query displays the needed results as you can see in report_Groups tab. But as the query on step B searches the whole columns of inner_report_Groups, there's only a single given date can be analysed (or the query interim results for other given dates should be placed in different columns of inner_report_Groups or at the different tab. Is there any way to give an alias for an interim result to refer it in a single cell formula instead of keeping it on different tab?
I would like to perform a multi criteria search of data in a column- contains data of check boxes(more than one option chosen).
For a clearer picture of what I am trying to do, screenshot below is a question in a form
Data from the form are saved in sheets like below,
So my concern here is if I would like to search/filter for the rows that contain "Commercial", the rows with Commercial,Engineering doesn't show up. That's definitely not an effective search.
Any advise on how can I go about this issue is kindly appreciated. If
Let's say you have your form in the response sheet in columns A to P, with the multiple choice in col D. If you want to filter your data on the word 'Commercial' you can either do:
=filter(A2:P, regexmatch(A2:P, "Commercial"))
or use query():
=query(A2:P, "select * where B contains 'Commercial' ")
Note: depending on your locale you may have to change the commas to semi-colons in order for the formulas to work.
I hope that helps ?
Following JPV's answer, I developed a line to make the query useful if you want to cross two categories. Let's suppose that someone in your checkbox example had picked all the options (IT, HR, Commercial, Engineering); and that you have created the cell with the dropdown option box in cell B1 with all your options, as JPV said.
Then, you want to filter and see all the people who had chosen IT and Commercial. You would, for that, create a second cell with the dropdown option box in, lets say C1; and then your query would be:
=query(A2:P, "select * where B contains '"&B1&"' and B contains '"&C1&"' ")
=FILTER(MOBILE!A2:E2000, ISNUMBER(SEARCH(A1,MOBILE!A2:A2000)))
SEARCH function will return a number of the position of the searched word (A1) in the searched strings in range (MOBILE!A2:A2000).
If the result of search is a number (ISNUMBER), then filter will return the TRUE rows result from the range MOBILE!A2:E2000.