Google Sheet Advanced Search using Query function - google-sheets

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.

Related

How to use the sum function when already using an indirect function in googlesheets?

=SUM((INDIRECT("'Week " & ROW()-6) & "'!$AH$28"),(INDIRECT("'Week " & ROW()-6) & "'!$AI$28"))
What I'm trying to do is:
Find a sheet name that has "Week" and "[number]" in the sheet name. (the number is the current row -6)
On that sheet found, I then want to sum up a range between cells AH28 and AV28. (I thought maybe it could work by manually adding the indirect part and the new cell number)
I'm pretty certain step 1 works, as I use a similar code/function in another sheet.
Am I not using the SUM part of the function right?
Do you know why this isn't working please?
Thank you!
=SUM((INDIRECT("'Week " & ROW()-6) & "'!$AH$28"),(INDIRECT("'Week " & ROW()-6) & "'!$AI$28"))
I get a #REF error saying that parameter "Week 2" is not a valid cell/range reference.
Alternatively, I could use =IFERROR(SUM('Week 1'!$AH$28:$AV$28),""), but I'm trying to avoid changing the week number of the sheet name manually many times.
I don't know how your data is structured. But if you are currently referring correctly to each cell, use SUM as you would with tho cell references, with ":"
=SUM(INDIRECT("'Week " & ROW()-6 & "'!$AH$28"):INDIRECT("'Week " & ROW()-6 & "'!$AI$28"))

How can I search for data in Google Sheets using multiple keywords?

I am trying to make a search box in google sheets which searches data based on keywords. This is specific to a spare parts inventory system. Each item is defined by 5 columns namely Type, Part Name, Part Number, Price, Stock.
One example of an item would be "Lockstitch","Needle Bar Bush","229-10312 / 331-2312", "500", "3000".
In a separate sheet, I am trying to make a search box where I put in keywords like "Lockstich" "Bush" and the result should display.
I have tried concatenating the column name into one string and concatenating the keywords and matching them using QUERY function, but the problem that arises is that when I try to search "lockstitch bush" it doesn't give result because it does not contain in the string "Lockstitch Needle Bar Bush 229-10312 / 331-2312 500 3000"
I want the code to separately search each keyword in the combined string and give out results matching the keywords
you can try like this:
=FILTER(A2:E6, REGEXMATCH(TRANSPOSE(QUERY(TRANSPOSE(LOWER(A2:E6)),,999^99)),
TEXTJOIN("|", 1, SPLIT(LOWER(H1), " "))))
or more strict:
=ARRAYFORMULA(QUERY({A2:E6, TRANSPOSE(QUERY(TRANSPOSE(A2:E6),,999^99))},
"select Col1,Col2,Col3,Col4,Col5
where "&TEXTJOIN(" and ", 1, IF(TRANSPOSE(SPLIT(H1, " "))<>"",
"lower(Col6) contains '"&TRANSPOSE(SPLIT(LOWER(H1), " "))&"'", ))&"", 0))

Formula that needs to return information based on two criterias

I have reached a roadblock when it comes to a formula that we are currently working on for works purposes.
What the formula needs to achieve is bring back information based on two cells' information. We have gotten it to work with one cell using the following formula:
"CONCATENATE(INDEX(IF(sheet2!c:c = c1, "company: " & char(10, ""))))"
Now this brings back some information but not as defined as we would like it to be, so we need to bring in a second cell, using
"IF(sheet2!c:c = c1 & ..."
brings back no results, leaving the cell empty. Using IFS produces either an error or name, as does AND(, OR(, MATCH(, CHOOSE(.
Any of your learned input will be greatly appreciated.
your syntax is unusual. try:
=ARRAYFORMULA(IF((Sheet2!C:C=C1)*(Sheet2!D:D=D1), "company: "&CHAR(10), ))
or with + mimicking OR:
=ARRAYFORMULA(IF((Sheet2!C:C=C1)+(Sheet2!D:D=D1), "company: "&CHAR(10), ))

Error when using match and indirect in Google Sheet

I have to make a conditional formating formula with cross-sheet references.
Basically I have many sheets, one with existing words, and another one with words we have to add. I want to highlight in "Feuille 6" the words that are already in "Existant". I tried many formulas, I read the doc, I still can't figure it out.
Quick edit : equiv = match, and ligne = row, it's just google sheet translating words into French..
Here's the formula I think I should use, but it's not working
=EQUIV(A,indirect("Sheet1!A"&LIGNE()))
Here's what the Feuille 6 looks like
Again, there should be highlighted words in Feuille 6, like " Action ", which already exists in the sheet " Existant ".
I tried replacing "Sheet1 "with "Existant" too.
Any tip please?
Thanks !
Try:
Assuming the sheet Existant has values in columns A to Z , and you are highlighting cells in column A
=countif(indirect("Existant!A:Z"), A1)

Dynamic number of WHERE conditions in Google Sheet query function

I'm building a spreadsheet that can be used to import and then filter wireshark capture .csv's. The idea is - you import the .csv into the second tab, and on the first tab you are able to display the data based on a number of include/exclude filters. Here is a dummy sheet for reference:
https://docs.google.com/spreadsheets/d/17TtZHRiXCaH1XClq5SGRdIuyLZnMOrl6Ygrbfo9BbfM/edit?usp=sharing
As you can see in the spreadsheet, I have four possible "include" values and four possible "exclude" values, each being determined by selection of a drop down-list. The intention is for the QUERY() function in cell A6 to display the data based on these filters.
Example of the filter at work
I know how to use WHERE to do it for a single filter condition:
=query('Import CSV Here'!1:349,"select * where ("&B4&"="&B2&")")
And how to do it for multiple filter conditions:
=query('Import CSV Here'!1:349,"select * where ("&B4&"="&B2&") and ("&C4&"="&C2&")" )
What I can't figure out is how to write the QUERY function so that it only factors in a WHERE condition for filter columns that aren't blank (and therefore have been actively populated from their drop down menus). Is there an efficient way to do this?
You can wrap each filter condition in an if clause and use put something that evaluates to true if it is blank.
=query(
'Import CSV Here'!1:349,
"select * WHERE " &
IF(ISBLANK(B2), "1=1", B4 & "=" & B2) &
" and " & IF(ISBLANK(C2), "1=1", C4 & "=" & C2) )

Resources