Hi all,
I'm trying to get a formula to do exact and partial matches.
I use INDEX(...MATCH(...)) to look for exact matches and if fails, then I try to do partial matches using VLOOKUP() but is not showing expected output.
The partial match should show the "best match", this is select the number that has more numbers in common in same order. In other words, select the number that
shares the longest common prefix. The minimun prefix length to match would be 4 digits, is only match 3 digits or none show "NOT FOUND".
I hope make sense, thanks for any help.
Examples:
For number 50660000 in D3, the more similar numbers in column B are 5067000,5063005,506600002 and within these 3, the more similar is 506600002 because shares common
prefix of length 8.
50660000
506600002
For number 3520913 in D6, the more similar numbers in column B are 352021,352621,352091000 and within these 3, the more similar is 352091000 because shares common
prefix of length 6.
3520913
352091000
For number 13603399617 in D9, the more similar numbers in column B are 1360339,136033 and within these 2, the more similar is 1360339 because shares common prefix of length 7.
13603399617
1360339
For number 32486 in D7, the more similar number in column B is 32475 but only has the first 3 numbers in common, so show "NOT FOUND"
32486
32475
I'm trying to get a formula to do exact and partial matches.
I use INDEX(...MATCH(...)) to look for exact matches and if fails, then I try to do partial matches using VLOOKUP() but is not showing expected output.
The partial match should show the "best match", this is select the number that has more numbers in common in same order. In other words, select the number that
shares the longest common prefix. The minimun prefix length to match would be 4 digits, is only match 3 digits or none show "NOT FOUND".
I hope make sense, thanks for any help.
Examples:
For number 50660000 in D3, the more similar numbers in column B are 5067000,5063005,506600002 and within these 3, the more similar is 506600002 because shares common
prefix of length 8.
50660000
506600002
For number 3520913 in D6, the more similar numbers in column B are 352021,352621,352091000 and within these 3, the more similar is 352091000 because shares common
prefix of length 6.
3520913
352091000
For number 13603399617 in D9, the more similar numbers in column B are 1360339,136033 and within these 2, the more similar is 1360339 because shares common prefix of length 7.
13603399617
1360339
For number 32486 in D7, the more similar number in column B is 32475 but only has the first 3 numbers in common, so show "NOT FOUND"
32486
32475
Excel Formula:
=IFERROR(IFERROR(
INDEX($A$2:$A$29,MATCH(D2,$B$2:$B29,0)), --> This do exact match
VLOOKUP(D2&"*",$A$1:$B$29,2,TRUE) --> If exact match fails, try partial match
),
"NOT FOUND")
Search numbers.xlsx | ||||||||
---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | |||
1 | CODE | NUMBER | NUMBER | CURRENT OUTPUT | EXPECTED OUTPUT | |||
2 | XZS90 | 5067000 | 50660000 | NOT FOUND | XZS76 | |||
3 | XZS78 | 5063005 | 423780000 | NOT FOUND | XZS13 | |||
4 | XZS76 | 506600002 | 39370 | XZS81 | XZS81 | |||
5 | XZS29 | 32475 | 39335 | NOT FOUND | NOT FOUND | |||
6 | XZS39 | 4206080055 | 3520913 | NOT FOUND | XZS71 | |||
7 | XZS64 | 420602 | 32486 | NOT FOUND | NOT FOUND | |||
8 | XZS35 | 42379 | 1807631 | NOT FOUND | NOT FOUND | |||
9 | XZS13 | 4237800 | 13603399617 | NOT FOUND | XZS99 | |||
10 | XZS96 | 4237807672 | 5257000 | XZS05 | XZS05 | |||
11 | XZS16 | 42397030 | ||||||
12 | XZS05 | 5257000 | ||||||
13 | XZS47 | 421903 | ||||||
14 | XZS15 | 421905 | ||||||
15 | XZS40 | 4206020899 | ||||||
16 | XZS56 | 18072141180 | ||||||
17 | XZS03 | 18072144650 | ||||||
18 | XZS27 | 1809859 | ||||||
19 | XZS99 | 1360339 | ||||||
20 | XZS41 | 136033 | ||||||
21 | XZS98 | 1802692 | ||||||
22 | XZS60 | 180825 | ||||||
23 | XZS93 | 393533000 | ||||||
24 | XZS58 | 3932059 | ||||||
25 | XZS31 | 393205800448 | ||||||
26 | XZS89 | 352021 | ||||||
27 | XZS46 | 352621 | ||||||
28 | XZS71 | 352091000 | ||||||
29 | XZS81 | 39370 | ||||||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
E2:E10 | E2 | =IFERROR(IFERROR( INDEX($A$2:$A$29,MATCH(D2,$B$2:$B29,0)), VLOOKUP(D2&"*",$A$1:$B$29,2,TRUE) ), "NOT FOUND") |