I have two columns of values of which the second includes a subset of the first. I'm parsing partial matches from the first column with:
=query(A:A, "select A where A ends with 'x'")
It works fine. How would you modify it in order to exclude the shared values?
Here's an example:
A is where we're parsing from, B is the subset we want to discard, C would be the desired result:
filter values to exclude common values with column B
return only values ending in 'x'
Edit
To solve this, you first may need to exclude values from column B, then query result to match only pattern '%x'. Try this formula:
=QUERY(FILTER(A:A,REGEXMATCH(A:A,JOIN("|",FILTER(B:B,B:B<>"")))=false),
"select Col1 where Col1 like '%x'")
Edit #2
Special symbols for regular expressions are \ + * ? [ ^ ] $ ( ) { } = ! < > | : -
If such symbols are met in your data, you need to escape them by \ in order to use regular expressions. So formula REGEXMATCH in this case won't work properly if column B contains special symbols. Possible solution is to replace them like this: [symbol] → [\symbol]. For example, to replece ():
=REGEXREPLACE(text ;"(\(|\)|\*)";"\\$1")
Try using this formula in column C to get the result:
=QUERY(FILTER(A:A,REGEXMATCH(A:A,
REGEXREPLACE( JOIN("|",FILTER(B:B,B:B<>""));"(\(|\)|\*)";"\\$1"))=false),
"select Col1 where Col1 like '%x'")
Original answer
may be using not keyword will work:
=query(A:A, "select A where not A ends with 'x'")
the same as:
=query(A:A, "select A where not A like '%x'")
Related
I have two tabs that list names along with other data. I would like to query "Leads Weekly" A:E and have that data pull the value of column E where A matches C on another Sheet. ?
I've tried query formulas : =QUERY('Leads weekly'!A:E, "Select E where A contains 'MELISSA SURO'")
which works, but I'm looking for something scalable, I have over 500 names I would have to type in.
try:
=QUERY('Leads weekly'!A:E,
"select E where A matches '"&TEXTJOIN("|", 1, Sheet!C:C)&"'", )
I am trying to get a google sheet to search for a specific cell in a table. The headers change so it might be A6 one week and then A9 the other and so on.
Once it's found that row, I want it to search and pull all of that departments names and data for the column its matched with.
I am 23 sheets in and my heads hit a brick wall and I just can figure it out.
You can try:
=QUERY({A:B,INDEX(A:G,0,MATCH(D25,1:1,0))},"SELECT * WHERE Col2='" & LOWER(F25) & "'")
Note - you should remove unnecessary spaces. In sample data, they were in cells C1 and D25.
Try this:
=QUERY(
FILTER(
IFS(
TRIM(1:20) = "", 0,
ISNUMBER(1:20), 1:20,
True, LOWER(TRIM(1:20))
),
1:1 <> ""
),
"SELECT Col1, Col2, Col" & MATCH(TRIM(D25), ARRAYFORMULA(TRIM(1:1)),) & "
WHERE Col2 = '" & LOWER(F25) & "'",
1
)
You can use a combination of CHAR(MATCH...)) and Query formula to get this
=QUERY('Sheet Name'!A1:G20,"SELECT A, B, "&CHAR(MATCH("Log 4",'Sheet Name'!A1:G1)+64)&" WHERE B='w'")
Above formula only works till column Z, but thanks to Kishkin's comment below, you can use it beyond Z like this:
=QUERY('Sheet Name'!A1:G20,"SELECT A, B, `" & =REGEXEXTRACT(ADDRESS(1, MATCH("Log 4",'Sheet Name'!A1:G1), 4), "\D+") & "` WHERE B='w'")
You use SUBSTITUTE instead of REGEXTRACT too. You can refer to this Question.
the CHAR(MATCH...)) gets the column name of the desired Log
you can then use the column name to include that column in Query select statement
In the MATCH formula, you can also dynamically Match for a cell reference instead of specifying "Log 4" manually
Note: This is basically splitting the Query formula and concatenating it with another formula. So the &, ' and " symbols are really important
Sample Screenshot:
I have a 'Raw Invoice' tab which is an excel file copy/pasted directly over. I'm then trying to format the data in the 'Invoices' tab in that column order using a query. I need to be able to break out the Student Name into two separate columns, hopefully within the query itself. Preferably it would then change it so column C is Last Name and column D is First name and the rest of columns shift over one.
I don't know if there's a way to perform a SPLIT function within the query. Right now I'm using a clunky method by doing a VLOOKUP on the student ID to get the names from another tab (not included in the Sample GS cuz it's an importrange from a work file), but it then creates two separate queries. Ideally I can somehow split column C within one query, but am getting lost by nesting queries and arrays together. I might be able to use REGEXEXTRACT, but again get lost in where to put it in the query or whether that's overkill.
QUERY('Raw Invoice'!$A:$I,"Select F,B,A, 'Bobs Diner',D,G,I where C is not null label 'Bobs Diner' 'Company' Format F 'M/DD/YYYY' ",1)
Link to sheet.
split in query arguments is not possible but you can do:
=ARRAYFORMULA(QUERY({IFERROR(SPLIT('Raw Invoice'!A:A, ", ")), 'Raw Invoice'!B:I},
"select Col7,Col3,Col1,Col2,'Bobs Diner',Col5,Col8,Col10
where Col3 is not null
label 'Bobs Diner' 'Company'
format Col7 'M/DD/YYYY'", 1))
Wat I suggest is to implement in Row Invoice
=arrayformula(split(A3:A,","))
and then
=QUERY('Raw Invoice'!$A:$K,"Select F,B,J,K, 'Bobs Diner',D,G,I where C is not null label 'Bobs Diner' 'Company' Format F 'M/DD/YYYY' ",1)
I'm trying to run a simple query to condense a list of information from a column (which contains a consistent data type), removing blanks. I have the following code:
=query({Z:Z},"select * WHERE NOT Z =''")
This produces the error: Unable to parse query string for Function QUERY parameter 2: NO_COLUMN: Z.
I've encountered similar issues with query elsewhere - for some reason not yet figured out by my brain, my columns somehow don't exist. I've tried using col26, col1, and everything between col1 and col30, to no avail. While I could workaround this particular simple situation with more of a filter() function, I'd like to better understand why my column's aren't computing. I'd appreciate any clarification on this.
Try this:
=query({Z:Z},"select * WHERE Col1 is not null")
When using curly brackets {} instead of normal ones () you can not use the column letters any more but the number of the column.
Example: When you have =query({D1:F10},"select * WHERE Col3 is not null") it means F is not null (D=Col1, E=Col2, F=Col3)
you can either use:
=QUERY({Z:Z}, "where Col1 !=''")
or:
=QUERY(Z:Z, "where Z !=''")
I am currently working in the following spreadsheet
https://docs.google.com/spreadsheets/d/13KfjUhWSB-BjGyC1G8f8i8o4SPd1kFFLkjN7D6VY8Lk/edit#gid=993210576
In which I am importing data from another worksheet using IMPORTRANGE, and writing a QUERY to match the cells in column B, which correspond to a specific part number, to their corresponding cut quantity found in Column D of the imported sheet. The query I have written is as follows.
=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1kFK-ZW8QjtsLYY5twdoMNTdqobGNWIV8nAFBRdouE28/edit#gid=473793446",
"FABRICATION LOG!A78169:K"), "Select Col3 where Col4 = "&B3&" limit 1", 0)`
And is returning the error message:
Unable to parse query string for Function QUERY parameter 2: NO_COLUMN: WFR332703
I have used ImportRange for the sheet I am linking to in sheet1 of the spreadsheet linked above, and allowed access, so the error is not there.
Sheet1 is there to display the values returned for the IMPORTRANGE so that I can manually look up values I am expecting to get. Now for some of these cells, I expect to not get a value, as these will not be in the sheet I'm importing. But for others, I am expecting a numerical value, which is not being returned. I suspect this may have something to do with the fact that there is a mismatch between Datatypes since the entries in column b are both letters and numbers, but this is only a hunch with no actual facts to back it up. If anyone has any suggestions It'd be greatly appreciated.
first, paste this into some cell and connect you sheets by allowing access:
=IMPORTRANGE("1kFK-ZW8QjtsLYY5twdoMNTdqobGNWIV8nAFBRdouE28", "FABRICATION LOG!A1")
then use the formula:
=QUERY(IMPORTRANGE("1kFK-ZW8QjtsLYY5twdoMNTdqobGNWIV8nAFBRdouE28",
"FABRICATION LOG!A78169:D"),
"select Col3
where Col4 = '"&B3&"'
limit 1", 0)
if cell B3 is number use:
=QUERY(IMPORTRANGE("1kFK-ZW8QjtsLYY5twdoMNTdqobGNWIV8nAFBRdouE28",
"FABRICATION LOG!A78169:D"),
"select Col3
where Col4 = "&B3&"
limit 1", 0)
I came here because I had a query like:
=Query(Data, "select * where i < 70", 1)
What fixed it was changing to:
=Query(Data, "select * where I < 70", 1)
The column in the where clause needs to be upper case if its a letter higher than 'd'.