Check a column of strings on another column of substrings - google-sheets

I want to check a column of strings on another column of substrings to see the strings contain any of the substrings.
I am currently attempting =SEARCH(lower('Sheet2'!$A$1:$A$100),lower(B1)) and would like a True/False response.
Thanks in advance.
An example of Sheet2 would be:
A
1 Hello
2 Hi
3 I said she
an example of Sheet1 with the expected result in column C would be:
A B C
1 23 There are many FALSE
2 45 I said he is slow FALSE
3 3 I said she is bad TRUE
4 78 he yelled hello TRUE
Any help is appreciated
EDIT: link to example - https://docs.google.com/spreadsheets/d/1c2pskSYsGs12Yjbn-5gORQ22mDSaC9cSnp1nWeULlf4/edit?usp=sharing

In Sheet1!C1:
=ArrayFormula(IF(B:B="",,REGEXMATCH(LOWER(B:B),JOIN("|","\b"&FILTER(LOWER(Sheet2!A:A),Sheet2!A:A<>"")&"\b"))))
You haven't shared a link to a spreadsheet, so this is untested on any actual data. Your locale is also unknown, which may required modifications as well. So if this formula doesn't work as provided, share a link to your sample spreadsheet.

Related

google sheets (h)lookup last non-null value in specific column

I'm trying to populate a column with the last known price at the end of a batch of orders.
Please see an example attached.
I need the last price known from columns "price". Please note that there is not always value.
I tried something like this : =LOOKUP(B2:H2,"price",B3:H3<>"")
But it didn't really work.
(the nos 18 and 3 in column "I" are just examples. I need the green 3 results),thx.
Maybe try:
=INDEX(FILTER(B3:H3,B$2:H$2="price"),COUNTIFS(B$2:H$2,"price",B3:H3,"<>"))
If there could be empty gaps in your data, try this alternative:
=INDEX(A3:H3,MAX(COLUMN(A3:H3)*(A$2:H$2="price")*(A3:H3<>"")))

Trying to filter a query using data validation drop down - numerical options work, but not a combination of numbers/letters [duplicate]

This question already has answers here:
Query is ignoring string (non numeric) value
(2 answers)
Closed 5 months ago.
Here is a copy of my sheet https://docs.google.com/spreadsheets/d/1b7ofD9f02yKiIvGYfCBi_GdhkRtgTAoY2NpftJmZaDQ/edit?usp=sharing
So my query is on the front tab 'Overall' in D1
=query(Data!A1:G,"SELECT * WHERE 1=1 "&IF(A2="All Raids",""," AND A contains "&A2&" ") &IF(B2="All Classes",""," AND LOWER(B) = LOWER('"&B2&"') "),1)
On the datasheet, I have people listen in raids 1,2 and 3.. and it works fine. However, if I were to change a value to something like BWL1 or BWL2, it will not display.
I got this code from a youtube tutorial, so I don't understand it 100%, but basically the "a2=all raids","" part is just to remove any filters, then the remaining is filtered by my drop-down menus, &A2& and &B2&.
Any ideas?
I've tried using A CONTAINS "&A2" instead of A = "&A2&", I just cant figure out a workaround to where any value (numberical+lettered) listed in my Datasheet column A works.
Thank you in advance for your time, I hope this makes sense :)
That's a known issue with query() function: query() has trouble with mixed datatypes (numeric and text in column A). To avoid this you can convert column A to text. See if this formula works
=query({ArrayFormula(to_text(Data!A1:A)), Data!B1:G},"SELECT * WHERE 1=1 "&IF(A2="All Raids","", " AND Col1 contains '"&A2&"'") &IF(B2="All Classes",""," AND LOWER(Col2) = LOWER('"&B2&"') "),1)
Note that, because of the use of 'contains' when '1' is selected in A2, it will also show rows containing BWL1. If you don't want that, change 'contains' to '='.

How can I split cell values and compare the results with those of another cell?

I have already asked a similar question in another thread which was wonderfully answered by someone. However, it seems like that even if it did help, it was not 100% ok for all my GSheets and different projects. So I have been able to get more useful data from my source and I think that I would be able to have a bulletproof solution if I am able to find the good formula...
So my data looks like that:
Column A has a list separated by semicolons. Copy paste looks like that "Potato ; Banana ; Apple".
Column B has a list of IDs, which are linked to the data in column A. So Potato is ID 1871, Banana is ID 1890 and Apple is ID 1840. Copy paste of date is: "1871 ; 1890 ; 1840"
Column C should output formula with the value "Banana", because his ID is the highest of all (1890 > 1871 > 1840).
I have tried a lot of different things. Overall I tried to SPLIT the values with " ; " and create one array where I would try to sort them from the column or row where the IDs would be. I wasn't sure how to merge both results...
I tried to study the ARRAYFORMULA() function to see if it would help. gSheets is very nice to work with, but I come from a world of PHP where I would write 7 lines of code to achieve my goals, where here I need to do only 1 line of code and it is a challenge for me.
Any help is appreciated to find the formula in cell C1 that would get the value from A1 that has the highest ID in B1.
=ARRAYFORMULA(HLOOKUP(MAX(TRIM(SPLIT(B1, ";"))*1),
{TRIM(SPLIT(B1, ";"))*1; TRIM(SPLIT(A1, ";"))}, 2, 0))

Conditional formatting not working with 'countif' function in Google Sheets

I'm trying to apply a simple custom formula in a conditional formatting rule in Google Sheets, but it's not working for me and I can't understand why.
I have two sheets. The first sheet contains a series of rows, that start with an id:
ID
50013 50 13 Member of the City Council 3 4
50082 50 82 Member of the City Council 3 62
50083 50 83 Member of the City Council 3 130
Then my second sheet contains another similar list of rows, which is a subset of those in the first sheet. What I'm trying to do is highlight the rows in the first sheet where the "ID" field (indicated above) is in the subset in the second sheet.
The rule I'm tryin to use is:
countif('Bernie Intersect 1'!$A$2:$A$22, A2)
But when I put it into the conditional formatting conditional field, I don't get the desired result. I can't see the output, but evidently the field is not coming back with TRUE...
I thought that I might need an = in front of the expression, but if I add that I get an error that the formula is invalid.
Does anyone know what I might be doing wrong here?
Conditional formatting formulas do not allow explicit references to other sheets. Use indirect to get around this restriction:
=countif(indirect("'Bernie Intersect 1'!A2:A22"), $A2)
With indirect there is no need to say that A2:A22 are absolute references, since they are in the string format anyway; within indirect everything is absolute.

Small in arrayformula (Google Spreadsheet)

I have 5 columns of numbers that I want to sort per row into another set of columns. I figured I need to use small() (e.g. small(a2:e2,1) for f2; small(a2:e2,2) for g2 and so on). Is there away to iterate this for the next rows; if possible using only native google spreadsheet formulas?
Thanks in advance
I was able to make a temporary work around, but I had to use 3 cheat columns. It looks ok for now but I imagine it will be troublesome for really huge numbers.
Here's a sample sheet for reference: https://docs.google.com/spreadsheets/d/1MQTP2XkRsPRAnPQ5wLhkR8JoNVY6YOExVlOkkX8UeRs/edit#gid=0
The original data are in A3:E
The first cheat column (G3:G) simply creates a column of numbers from 1 to the largest number found in the source data. 1-9 is changed to 01-09 for easier searching. "#" is then added at the end-this will come handy later:
Cheat Column 1 =filter(if(row(A:A)=max(A:E)+1,ʺ#ʺ,text(row(A:A),ʺ00ʺ)),row(A:A)<=max(A:E)+1)
The second cheat column (H3:H) combines each row into a string separated by "-" with a "#" marker:
Cheat Column 2=filter(text(A3:A,ʺ00ʺ)&ʺ-ʺ&text(B3:B,ʺ00ʺ)&ʺ-ʺ&text(C3:C,ʺ00ʺ)&ʺ-ʺ&text(D3:D,ʺ00ʺ)&ʺ-ʺ&text(E3:E,ʺ00ʺ)&ʺ#ʺ,A3:A<>ʺʺ)
The last cheat column (I3:I) sorts each line (from cheat column 2) by finding each number from cheat column from 01 up to the max number, then the "#" char (this ensures that each line will still have the # end marker). "Find" will return the "position" of each number or an error if it's not found. By using "if", we can make "find" return the actual number or "" instead.
=filter(arrayformula(if(iferror(find(transpose(filter(G3:G,G3:G<>ʺʺ)),H3:H),ʺʺ), transpose(filter(G3:G,G3:G<>ʺʺ)),ʺʺ)),A3:A<>ʺʺ)
The formula above creates as many columns as there are numbers from cheat column 1. To prevent this, a "-" is added to each number then "Concatenate" is used to combine everything into one massive string with each set separated by "#". The string is then split using the "#" marker.
Cheat Column 3 =transpose(split(concatenate(filter(arrayformula(if(iferror(find(transpose(filter(G3:G,G3:G<>ʺʺ)),H3:H),ʺʺ),ʺ-ʺ&transpose(filter(G3:G,G3:G<>ʺʺ)),ʺʺ)),A3:A<>ʺʺ)),ʺ#ʺ))
Each number is then separated into each corresponding column by using mid().
Small 1 =filter(mid(I3:I,2,2)*1,A3:A<>ʺʺ)
Small 2 =filter(mid(I3:I,5,2)*1,A3:A<>ʺʺ)
Small 3 =filter(mid(I3:I,8,2)*1,A3:A<>ʺʺ)
Small 4 =filter(mid(I3:I,11,2)*1,A3:A<>ʺʺ)
Small 5 =filter(mid(I3:I,14,2)*1,A3:A<>ʺʺ)
Note that the formula above is only for numbers 1-99. For larger numbers, the Text() formulas should have more zeroes to correspond to the number of digits of the biggest number. The Mid() formulas should also be adjusted accordingly.
I would like to stress that I am very far from being a spreadsheet expert and that this solution is very "unoptimized". It requires several cheat columns; with the first one even having more rows than the original data. If anyone can help me get rid of the cheat columns (or at least the first one) I will be very grateful.
How about using SMALL like you mentioned in your question?
=small($A3:$E3,column()-columns($A3:$G3))
You will need to change the ranges accordingly. The last $G$3 is the cell just before the cell where the formula is placed.
Sample

Resources