Google Sheets query that searches multiple columns - google-sheets

I currently have a search function I got from a tutorial and I'm wondering how I can modify it so that when I type key words into B1 it will search for the key words in columns A thru G on the workshop tab instead of just column D. I left the code I currently have below:
=QUERY(Workshop!$A$1:$G,"SELECT * WHERE LOWER(D) LIKE LOWER(""%" &JOIN("%"") AND LOWER(D) LIKE LOWER(""%", SPLIT($B$1," "))&"%"")",1)
Here is a link to the sample spreadsheet:
https://docs.google.com/spreadsheets/d/1nCNMpe2peJUWerUP8fgjMHxTiIwgUyZoM5GAW1PnoQo/edit?usp=sharing
I tried replacing the "D" with "A:G" and I also tried replacing it with "A,B,C,D,E,F,G" and neither worked. I don't know what else to try, I am still so new to this! I couldn't find anything on Google about it either!

instead of searching through all columns you can collapse them into one and search it there and then not include it into the output:
=ARRAY_CONSTRAIN(IFERROR(QUERY({Workshop!A:G,
TRANSPOSE(QUERY(TRANSPOSE(Workshop!A:G),,99^99))},
"where lower(Col8) contains '"&LOWER(B1)&"'", 1)), 99^99, COLUMNS(A:G))
ofc there are like 20+ levels of how strict or smart you want that search to be...

Related

Exclude all values in a column on a different sheet from a Google Sheets Query

So I have the following query:
=QUERY('sheet - Users'!A1:S, "Select A,B,C,F,G,O,Q,S where Q >= 44223 and not lower(O) matches '.*archived.*|.*archived' and not lower(C) matches '.*admin.*|.*admin' and not UPPER(C) matches '.*SMB.*' and not C matches '.*Shared Mailbox.*' and S >=90",1)
This works perfectly fine (as convoluted as it is), however, I have a list of exceptions that I need to remove from the results (the list could change, so ideally this needs to be dynamic and not hard coded).
I did some digging around and found this example query:
=query(C2:C8,"select C where C<>'"&JOIN("' and C<>'",D2:D10)&"'"&""
But that doesn't seem to be working for me when I try to incorporate it into my query.
The data I need to exclude is on a sheet called: Exclusion List
And is in cells C2:C
Is anyone able to help?
Solution:
You can modify the exclusion list to reference C2:C from another sheet, like this:
=query(C2:C8,"select C where C<>'"&JOIN("' and C<>'",'Exclusion List'!C2:C)&"'"&""
Sample Query and Exclusion Sheet:

Google sheets query searching multiple columns with space seperator within a cell

Now this following query runs great on one column and does use a space as a search separator however it only seaches one column.
=QUERY(Data!A1:O, "SELECT * WHERE LOWER(N) LIKE LOWER(""%" &JOIN("%"") AND LOWER(N) LIKE LOWER(""%", SPLIT(B1," "))&"%"")",1)
However then I found this snippet and that searches the entire sheet but cannot separate words within a cell.
=ARRAY_CONSTRAIN(IFERROR(QUERY({Data!A:O, TRANSPOSE(QUERY(TRANSPOSE(Data!A:O),,99^99))}, "where lower(Col16) contains '"&LOWER(B1)&"'", 1)), 99^99, COLUMNS(A:O))
The issue is I want to search multiple of my columns namely D,E,G,H,M,N where M contain multiple words that should be searched separated by a comma and space since the data comes from a form.
Is there a way that makes it possible to achieve this?
Link to a very obfuscated sheet upon request data is somewhat similar yet document is very simplified and shortened.
https://docs.google.com/spreadsheets/d/1PxdObZsn62rQ3QeYVdy9HjToIHZsmw1d0cXK2jOuiC4/edit?usp=sharing
Solution
In this case you should use the same approach you were using before, but now when searching in the built Col16:
=ARRAY_CONSTRAIN(IFERROR(QUERY({Data!A1:O, TRANSPOSE(QUERY(TRANSPOSE(Data!A1:O),,99^99))}, "where lower(Col16) LIKE LOWER(""%" &JOIN("%"") AND LOWER(Col16) LIKE LOWER(""%", SPLIT(B1," "))&"%"")", 1)), 99^99, COLUMNS(A:O))

Is there a way to make a query with an importrange to mimic a sumif formula from another Google sheet?

I am encountering a capacity issue with one of my spreadsheets but certain information in the sheet still needs to be available to cross-reference. The original spreadsheet contains this formula:
=sumif(A:A,A2,N:N)=O2
I tried to do a direct transfer to the new spreadsheet by adding importranges like this:
=SUMIF(IMPORTRANGE("URL","Sheet1!A2:A"),IMPORTRANGE("URL","Sheet1!A2"),IMPORTRANGE("URL","Sheet1!N2:N")=IMPORTRANGE("URL","Sheet1!O2")
The equation keeps putting out an error saying "argument must be a range". Then I tried to write it out as a query like this:
=QUERY(AND(IMPORTRANGE("URL","Sheet1!A:A"),IMPORTRANGE("URL","Sheet1!N:N"),"SELECT SUM(CASE WHEN Col1=A2 THEN Col14)=O2"))
But the equation is showing FALSE as the result when it should say TRUE. I have attached an example spreadsheet so that these equations make more sense.
I also need the equation to take into account any new information that is placed on the new spreadsheet while also comparing it with the old info. I tried doing this to start with but then slowly realized the initial equation itself doesn't work.
=SUMIF(IMPORTRANGE("URL","Sheet1!A2:A"),IMPORTRANGE("URL","Sheet1!A2"),IMPORTRANGE("URL","Sheet1!N2:N"))=IMPORTRANGE("URL","Sheet1!O2")+SUMIF(A:A,A2,N:N)=O2
Any help is appreciated.
https://docs.google.com/spreadsheets/d/1q1cWh58p23dcQulQ4rz6v4iiDywEFHvcrvASao61xxo/edit#gid=0
use this formula instead of SUMIF:
=ARRAYFORMULA(IF(LEN(
IMPORTRANGE("1q1cWh58p23dcQulQ4rz6v4iiDywEFHvcrvASao61xxo","Sheet1!C2:C")),
IF(IFERROR(VLOOKUP(
IMPORTRANGE("1q1cWh58p23dcQulQ4rz6v4iiDywEFHvcrvASao61xxo","Sheet1!C2:C"),
QUERY(IMPORTRANGE("1q1cWh58p23dcQulQ4rz6v4iiDywEFHvcrvASao61xxo","Sheet1!A2:N"),
"select Col3,sum(Col14) where Col1 is not null group by Col3 label sum(Col14)''"),2,0))=
IMPORTRANGE("1q1cWh58p23dcQulQ4rz6v4iiDywEFHvcrvASao61xxo","Sheet1!O2:O"), TRUE, FALSE),))

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)

Select columns by name rather than letter in Google Query Language (GQL) with Google Spreadsheets? [duplicate]

This question already has answers here:
Google Sheets QUERY Function: Select Columns by Name
(2 answers)
Closed 4 months ago.
newbie question, is it possible to select columns by name rather than letter when using Google Query Language with Google Spreadsheets?
This works fine for me: "SELECT A, COUNT(B) GROUP BY A"
It'd be great if I could use the column headers in the first row, more like a database, as in:
"SELECT student, COUNT(detention) GROUP BY student"
I suspect it's not possible, but hope this yet another case where my Internet search skills failed me.
This is currently not possible. The GQL documentation states[1] "Columns are referenced by the identifiers (not by labels). For example, in a Google Spreadsheet, column identifiers are the one or two character column letter (A, B, C, ...)."
If you want to do this in a spreadsheet it is possible with the following formula to convert a column header name into a letter (some tweaking might be required +1 (might be +2)). It also relies on column headers being unique and not containing commas
=REGEXEXTRACT(ADDRESS(1,COUNTA(SPLIT(LEFT(JOIN(",",TRANSPOSE(1:1)),FIND("your_column_name",JOIN(",",TRANSPOSE(1:1)))),","))+1,4);"[a-zA-Z]+")
[1] https://developers.google.com/chart/interactive/docs/querylanguage#Select
A little simpler:
SELECT "&SUBSTITUTE(ADDRESS(1,MATCH("student",Sheet1!A1:B1,0),4),1,"")&", COUNT("&SUBSTITUTE(ADDRESS(1,MATCH("detention",Sheet1!A1:B1,0),4),1,"")&") GROUP BY "&SUBSTITUTE(ADDRESS(1,MATCH("student",Sheet1!A1:B1,0),4),1,"")
Example in Google Sheets
Detailed explanation
I found that when you use IMPORTRANGE function on external ranges it converts from a letter to a column number, and will help you in this matter.
I've wanted to select a column based on its field name, but the problem for me was that the column to look at was likely to change in the future. So what I did was use the MATCH function to identify the column, so it looks something like
=QUERY(IMPORTRANGE("spreadsheet url","NamedRange"),"SELECT Col"&MATCH("FieldName",FieldNameRowAddress/RangeName,FALSE)")
The funny thing is you have to allow permission to access itself.
I've named my ranges that I'm importing to make it even more future proof.
if you really want you can fake it:
=LAMBDA(student, detention, QUERY({A1:B5},
"SELECT "&student&", COUNT("&detention&") GROUP BY "&student, 1))
("Col"&MATCH("student", A1:B1, ),
"Col"&MATCH("detention", A1:B1, ))

Resources