Sep 17 2024 08:07 AM - edited Sep 17 2024 08:19 AM
Hi MS Community,
I have the following worksheet. In the Orders Tab, I need to be able to filter out the "Fruit" from the "Sentence".
Sheet1 = Fruits
Sheet2 = Orders
In Fruits:
A | |
1 | apple |
2 | pear |
3 | banana |
In Orders:
Sentence | Fruit | |
1 | James buy apple | apple |
2 | Peter sell pear | pear |
3 | Banana from japan | banana |
4 | apple keeps the doctor away | apple |
5 | Do you sell durian? | Invalid |
Preferably, casing can be ignored. I was trying out Index & Match but it didn't work (pls ignore the rows and column number as I was trying to simply using fruits).
=INDEX(fruit!A1:A3,MATCH("*"&fruit!A1&"*",C1:C4,0)) |
Kind Regards
Sep 17 2024 08:38 AM - edited Sep 17 2024 08:40 AM
Solutionhere are 2 options:
=LET(a,TEXTJOIN(",",1,IF(ISNUMBER(SEARCH($I$1:$I$3,A1)),$I$1:$I$3,"")), IF(a<>"",a,"invalid"))
or
=IFERROR(TEXTJOIN(",",1,TEXTSPLIT(LOWER(A1),TEXTSPLIT(LOWER(A1),LOWER($I$1:$I$3),,1),,1)),"invalid")
where A1 is the sentence cell and I1:I3 is the list of fruit
notice that the first uses SEARCH so case ignored but needed the extra step if nothing found. in the second I could enclose an IFERROR but needed to convert everything to LOWER() to make case indepenent
Sep 18 2024 07:42 AM
Sep 18 2024 08:29 AM
Sep 18 2024 08:46 AM
Sep 19 2024 06:47 AM
Sorry I need ask another question after testing the code. I notice it shows all fruits in the sentence.
Is it possible to just have only 1 fruit, but have the flexibility to adjust which if necessary?
Sentence | Fruit | |
1 | James buy apple and pear | apple |
2 | Banana and durian for lunch | Durian |
Kind Regards
Sep 19 2024 07:21 AM
Oct 07 2024 05:36 AM - edited Oct 07 2024 05:37 AM
Hello @m_tarler , I'm back again.
So I tested around your formula and came across another issue. If you can see the table sample below, it should explain. Basically the code I should get from the Contract should be NJM, but becuz of the "Japan", it got JA as well.
Is it possible to ensure that the casing are matching as well? (Since all the codes are in uppercase).
Im using the "=LET" by the way
Tyvm
ListofCode |
NJM |
MPS |
32 |
JA |
E6 |
E6M |
Contract | getCode |
Naphtha C&F Japan Mini [NJM] - ICE NJM Block Nov-24 | NJM, JA |
Oct 07 2024 09:51 AM
Oct 08 2024 03:12 AM
Sep 17 2024 08:38 AM - edited Sep 17 2024 08:40 AM
Solutionhere are 2 options:
=LET(a,TEXTJOIN(",",1,IF(ISNUMBER(SEARCH($I$1:$I$3,A1)),$I$1:$I$3,"")), IF(a<>"",a,"invalid"))
or
=IFERROR(TEXTJOIN(",",1,TEXTSPLIT(LOWER(A1),TEXTSPLIT(LOWER(A1),LOWER($I$1:$I$3),,1),,1)),"invalid")
where A1 is the sentence cell and I1:I3 is the list of fruit
notice that the first uses SEARCH so case ignored but needed the extra step if nothing found. in the second I could enclose an IFERROR but needed to convert everything to LOWER() to make case indepenent