How to do multiple searches in an array formula? - regex

I'm working on trying to get some formula working that'll vastly improve my QOL at work. I want the formula to run 2 searches for keywords that will be present in my "Title" column and my "SKU" column then return results based on a key that I have located in a second tab.
The above screenshot is my key. If products contain any of the keywords in the title column then the corresponding category is automatically assigned.
In the example screenshot below I have the formula working to do 1 search. It's searching the "Title" column (B) against the Keywords column in the Key and if the word exists within the title it gives a result back based on the row that the result was on.
What I want to achieve is to do multiple searches within the same column. I want to be able to first do the search by "Title", if no results are returned then I want it to search via the "SKU" column against the Keywords and Categories in the Key (Columns C & D)
In the below screenshot I've tried wrapping it in an IF statement
IF(TITLESEARCH=""),(SKUSEARCH),(TITLESEARCH)
The results I'm getting back seem to be working for the first part of the IF statement. It's giving me back results that are correct for the first part of the IF statement, but the second part doesn't seem to be working correctly and I can't figure out why. Where it should be assigning the category "Accessories" it's just giving me "FALSE" instead.
Here's a link to the spreadsheet if anyone would like to take a look. I've been wracking my brain on this for a few days now and I feel like I've come a long way.
https://docs.google.com/spreadsheets/d/1548QMP5qeAIFrbraGD_lkJkQWzKF4Td6FR1KkcOHHJM/edit?usp=sharing
I'm quite new to Google Sheets and excel formula (especially on this level) so please be gentle. It feels like the mistake I'm making might be glaringly obvious.
https://exceljet.net/formula/categorize-text-with-keywords
This is what my formula is based on.
=IF(ARRAYFORMULA(INDEX('Array Key'!B:B,MATCH(TRUE,ISNUMBER(SEARCH('Array Key'!A:A,B234)),0)))="",(ARRAYFORMULA(INDEX('Array Key'!D:D,MATCH(TRUE,ISNUMBER(SEARCH('Array Key'!C:C,A234)),0),(ARRAYFORMULA(INDEX('Array Key'!B:B,MATCH(TRUE,ISNUMBER(SEARCH('Array Key'!A:A,B234)),0))))))))

delete all your formulas and simply use:
=ARRAYFORMULA(IF(LEN(B2:B), IF(IFERROR(VLOOKUP(REGEXEXTRACT(A2:A,
TEXTJOIN("|", 1, 'Array Key'!C3:C)),
'Array Key'!C3:D, 2, 0))="",
IFERROR(VLOOKUP(REGEXEXTRACT(B2:B,
TEXTJOIN("|", 1, 'Array Key'!A3:A)),
'Array Key'!A3:B, 2, 0)),
IFERROR(VLOOKUP(REGEXEXTRACT(A2:A,
TEXTJOIN("|", 1, 'Array Key'!C3:C)),
'Array Key'!C3:D, 2, 0))), ))

Related

Google sheets formulas for checking max and then writting name of person in a different cell

so I have been working on automating this table for the most performing person of the week on google sheets.
now on the column O i have top candidate, I want to run an if statement that would check through the values of each person. for example, for day 1 it would check from K3 to N3 once it gets the value, it should post the name of the candidate. That means for week 1, day 1, it would check and see that charles has the top performance and post "Charles" on the top candidate cell of the same row.
so far i know how to know ts easy getting the number between the cells which has the biggest value =max(K3:N3) but then combining it with an if statement that would know the cell on top... that got me worked up and still not found an answer
This formula should work:
=INDEX($K$2:N,1,MATCH(MAX($K3:$N3),$K3:$N3,0))
MATCH will find a specific column that has the max value of K3:N3, then INDEX will reference the value of the top column.
Sample Sheet:
use:
=ARRAYFORMULA(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IFNA(
IF(IF(K3:N="", "x", K3:N)=QUERY(TRANSPOSE(QUERY(TRANSPOSE(K3:N),
"select "&TEXTJOIN(",", 1, IF(LEN(J3:J),
"max(Col"&ROW(A3:A)-ROW(A3)+1&")", ))&"")),
"select Col2"), K2:N2, ))),,9^9))))

UNIQUE formula in Google Sheets for multiple ranges

I have a list of participants in column A. A full employee list in column B. I want to get the list of non-participants in column C. Basically 'B-A' but in list form.
'January' is the participants list:
try:
=FILTER(A:A; NOT(COUNTIF(B:B; A:A)))
It is always an added challenge to write formulas when we don't have access to actual date. But based on what I can see, try this formula in the top cell of any empty column:
=ArrayFormula({"My Header"; FILTER(R2:R,ISERROR(VLOOKUP(TRIM(R2:R),TRIM(T2:T),1,FALSE)))})
You can change "My Header" to something meaningful.
The next part means "FILTER in anything in the range R2:R that cannot be found [i.e., ISERROR(VLOOKUP(...))] in T2:T."
TRIM is used just to account for any accidental/stray spaces that may occur in either list, since that would result in no match if one or the other had extra space.
If this does not do what you expect, please share a link to a sample spreadsheet.

array formula and regexmatch won't follow through whole column

I am having an issue with an Array Formula where my current formula is:
=ArrayFormula(if(REGEXMATCH(B2,to_text('Order Form 1'!A2:A))=true,"Approved",A2:A))
I am:
1. matching the responseTimestamp (text) to the whole column of Orders received.
2. if it matches then show "Approved",
3. else, it should populate the Order not matched into that cell.
It populates in the "Pending" column correctly if it (regex)matches "B2";
however, I have more data in that column and would like it to perform this formula over "B2:B".
When I do this it doesn't populate the correct answer.
Can anyone offer insights or a solution?
Here is a link to a copy of my workbook: https://docs.google.com/spreadsheets/d/1utgP82XMkb8cOhKX2_taGqfluq6jHLNkOqUVJ31WHBM/edit?usp=sharing
Thank you in advance!
See if this works
=ArrayFormula(if(REGEXMATCH(B2:B,TEXTJOIN("|", 1, 'Order Form 1'!A2:A)),"Approved",A2:A))
Or, if you just want to list the values from A that don't match in B, try
=filter(A2:A6, isna(match(A2:A6, B2:B6,0)))
=filter(A2:A6, isna(match(A2:A6, B2:B6,0)))
Thank you JPV, your answer worked best for how my columns are arranged.

Fuzzy match on google sheets

I'm trying to fuzzy match two columns in google sheets, i've tried numerous formulas but I think it's going to come down to a script to help out.
I have a column with product ID's e.g.
E20067
and then I have another sheet with another column which has image url's relating to this product code such as
http://wholesale.test.com/product/E20067/web_images/E20067.jpg
http://wholesale.test.com/product/E20067/high_res/E20067.jpg
http://wholesale.test.com/product/E20067/high_res/E20067-2.jpg
What I'm wanting to do is "fuzzy" match both of these columns for their product ID, and then create a new column for each match. So it would have the product ID then on the same row in multiple columns each product image URL - like the image below:
Is there a way to do this in google sheets using a script or a formula?
In Google sheets there are a few powerful 'regex' formulas.
Suppose, you have ID list in column A, and URL list in column B
Then use formula:
=REGEXEXTRACT(B1,JOIN("|",$A$1:$A$3))
It will match one of ID's. Drag the formula down to see the result as in picture above.
See more info here
Old thread but, in case you find yourself here, search for my Google Sheets add-on called Flookup. It should do exactly what you want.
For this case, you can use this function:
Flookup (lookupValue, tableArray, lookupCol, indexNum, threshold, [rank], [range])
The parameter details are:
lookupValue: the value you're looking up
tableArray: the table you want to search
lookupCol: the column you want to search
indexNum: the column you want data to be returned from
threshold: the percentage similarity below which data shouldn't be returned
rank: the nth best match (i.e. if the first one isn't to your liking)
range: choose to return the percentage similarity or row number for each match
You can find out more at the official website (examples and such).
Please note that, whereas the OP appears to want the whole list of possible matches, Flookup will only return one result at a time.
Flookup can now return a list of all possible matches through its LRM mode.
Try the following. I am assuming the product codes are in Sheet1 and the URLs are in Sheet2. Both in column A:
=iferror(transpose(FILTER(Sheet2!$A$2:$A,Search("*"& A2 &"*",Sheet2!$A$2:$A))))
Copy down.
If you want to show the image instead of the url try:
=arrayformula(image(iferror(transpose(FILTER(Sheet2!$A$2:$A,Search("*"& A2 &"*",Sheet2!$A$2:$A))))))

How to Extract Numeric Range from Text in SQL

I am fairly new to SQL and I'm trying to extract some data from an ORACLE DB. My goal is to return rows where the query value lies in the range speicified by the "AA_SYNTAX" column in a table.
For example:
If the "AA_SYNTAX" column is 'p.G12_V14insR' and my search value is 13, I want to return that row. This column is organized as p.%number_%number%. So basically I want to return the two numerical values from this column and see if my query value is between them.
I have all the tables I need joined together and everything, just not sure how to construct a query like this. I know in regex I would do something like "\d+" but im not sure how to translate this into SQL.
Thanks
Using Oracle, you can use Regular Expressions to extract a number from the string.
More specifically, I would look into REGEXP_SUBSTR.
Using the date given in your example above, you could use:
with cte as
(
select 'p.G12_V14insR' as AA_SYNTAX from dual
)
select
REGEXP_SUBSTR(AA_SYNTAX,'p\.[[:alpha:]]+([[:digit:]]+)', 1, 1, NULL, 1) as Bottom
,REGEXP_SUBSTR(AA_SYNTAX,'\_[[:alpha:]]+([[:digit:]]+)', 1, 1, NULL, 1) as Top
from cte
I'm sure you could clean up the Regular Expression quite a bit, but, given this, you get the value of 14 for Top and 12 for Bottom.
Hope this helps move you in the right direction.