Forum Discussion
lookup
redridgie In the attached I copied your message text/example and my suggested formula:
=FILTER($A$17:$B$19,IFERROR(SEARCH($A$17:$A$19,A26),0)=1,"na")
my suggested formula does NOT agree with you sample results as I do NOT agree with your sample results. the category 423430 is not a subset of 42311 and the descriptions are not compatible. Note that this formula may pull more than 1 result so you may want a variation like:
=INDEX(SORT(FILTER($A$17:$B$19,IFERROR(SEARCH($A$17:$A$19,A26),0)=1,"na"),,-1),1,)
to get the longest matching code.
- mtarlerNov 04, 2022Silver Contributor
sure. As with all formulas you start in the middle most () so:
FILTER($A$17:$B$19,IFERROR(SEARCH($A$17:$A$19,A26),0)=1,"na")
this FILTER will filter the rows in A17:B19 if the condition is true and that condition is:IFERROR(SEARCH($A$17:$A$19,A26),0)=1
which is checking if it can find (i.e. search) the code from column A (A17:A19) inside this row's code value (A26) and it must be found starting at position 1 because a code like 123 we don't want to "match" inside a code 45123. the IFERROR is to catch when the code is NOT found and returns a 0 and hence a false.
So that filter will return all the rows from the code table that have codes that "match" and then that list is SORT from biggest to smallest
and finally it takes the 1st row (i.e. INDEX(..., 1, ) ). note we could also have used TAKE(... , 1) instead