Forum Discussion
Chaitanya_Palley
Jul 11, 2022Copper Contributor
String Match part of an array with repeated strings in duplicate records and return value
Hi,
I have a dataset like below in Sheet3 as in the screenshot with ID, country and number where country column has 2 letter country codes as array of multiple countries together unique to a ID and number combination. You can also see that there are more than one record with the combination of ID and number due to local language name.
In Sheet2, I have a 2 letter country code dropdown and a ID column, where when I select a country and against the ID, in the column H4 I should be able to fetch a number value from that dataset I mentioned earlier or just return multiple if the country exists in more than one combination.
For that I have written the below formula in the column H4 using vlookup to find the country string in the helper column I created which is the concatenation of ID and country column string and cover the scenarios of the country existing in first place after the ID which is of fixed length or middle position or the last position to tell me if the country exists in one combination or in more than one. However, in a scenario like in the current dataset where the country "FI" or "SE" exists in more than one combination moreover in the same position due to which vlookup is returning the value for the first instance of the match rather it should say multiple. Is it possible to tweak my current formula to also include these scenarios or should I have to rethink of a new logic on the whole ?
Formula:
IF(AND($G4<>"";$F4<>"");
IFERROR(IF(OR(AND((IFERROR(IF(VLOOKUP($G4&$F4&"*?";Sheet3!A2:E7;4;FALSE)<>0;"TRUE";
"FALSE");"FALSE"));(IFERROR(IF(VLOOKUP($G4&"*?"&$F4&"*?";Sheet3!A2:E7;4;FALSE)<>0;
"TRUE";"FALSE");"FALSE"));(IFERROR(IF(VLOOKUP($G4&"*?"&$F4;Sheet3!A2:E7;4;FALSE)<>0
;"TRUE";"FALSE");"FALSE"));(IFERROR(IF(VLOOKUP($G4&$F4;Sheet3!A2:E7;4;FALSE)<>0;
"TRUE";"FALSE");"FALSE")));
AND((IFERROR(IF(VLOOKUP($G4&$F4&"*?";Sheet3!A2:E7;4;FALSE)<>0;"TRUE";"FALSE");
"FALSE"));(IFERROR(IF(VLOOKUP($G4&"*?"&$F4&"*?";Sheet3!A2:E7;4;FALSE)<>0;"TRUE";
"FALSE");"FALSE")));AND((IFERROR(IF(VLOOKUP($G4&"*?"&$F4&"*?";Sheet3!A2:E7;4;FALSE)
<>0;"TRUE";"FALSE");"FALSE"));
(IFERROR(IF(VLOOKUP($G4&"*?"&$F4;Sheet3!A2:E7;4;FALSE)<>0;"TRUE";"FALSE");"FALSE"))
);AND((IFERROR(IF(VLOOKUP($G4&$F4&"*?";Sheet3!A2:E7;4;FALSE)<>0;"TRUE";"FALSE");
"FALSE"));(IFERROR(IF(VLOOKUP($G4&"*?"&$F4;Sheet3!A2:E7;4;FALSE)<>0;"TRUE";"FALSE")
;"FALSE")));AND((IFERROR(IF(VLOOKUP($G4&$F4&"*?";Sheet3!A2:E7;4;FALSE)<>0;"TRUE";
"FALSE");"FALSE"));(IFERROR(IF(VLOOKUP($G4&$F4;Sheet3!A2:E7;4;FALSE)<>0;"TRUE";
"FALSE");"FALSE")));AND((IFERROR(IF(VLOOKUP($G4&"*?"&$F4&"*?";Sheet3!A2:E7;4;FALSE)
<>0;"TRUE";"FALSE");"FALSE"));(IFERROR(IF(VLOOKUP($G4&$F4;Sheet3!A2:E7;4;FALSE)<>0;
"TRUE";"FALSE");"FALSE")));AND((IFERROR(IF(VLOOKUP($G4&"*?"&$F4;Sheet3!A2:E7;4;
FALSE)<>0;"TRUE";"FALSE");"FALSE"));(IFERROR(IF(VLOOKUP($G4&$F4;Sheet3!A2:E7;4;
FALSE)<>0;"TRUE";"FALSE");"FALSE"))));"Multiple";
IF(IFERROR(VLOOKUP($G4&"*?"&$F4&"*?";Sheet3!A2:E7;4;FALSE);"FALSE")<>"FALSE";
VLOOKUP($G4&"*?"&$F4&"*?";Sheet3!A2:E7;4;FALSE);
IF(IFERROR(VLOOKUP($G4&$F4&"*?";Sheet3!A2:E7;4;FALSE);"FALSE")<>"FALSE";
VLOOKUP($G4&$F4&"*?";Sheet3!A2:E7;4;FALSE);
IF(IFERROR(VLOOKUP($G4&"*?"&$F4;Sheet3!A2:E7;4;FALSE);"FALSE")<>"FALSE";
VLOOKUP($G4&"*?"&$F4;Sheet3!A2:E7;4;FALSE);
IF(VLOOKUP($G4&$F4;Sheet3!A2:E7;4;FALSE)<>0;
VLOOKUP($G4&$F4;Sheet3!A2:E7;4;FALSE);)))));"MISSING");"")
This is works correctly if the country is not repeated or even if repeats but is in a different position. Like it does for "NO" country. See, below:
Thanks,
Chaitanya Palley
=IF(SUM(N(IF((sheet3!$B$2:$B$7=sheet4!H7)*ISNUMBER(SEARCH(sheet4!G7,sheet3!$C$2:$C$7))=1,MATCH(IF((sheet3!$B$2:$B$7=sheet4!H7)*ISNUMBER(SEARCH(sheet4!G7,sheet3!$C$2:$C$7))=1,sheet3!$D$2:$D$7),IF((sheet3!$B$2:$B$7=sheet4!H7)*ISNUMBER(SEARCH(sheet4!G7,sheet3!$C$2:$C$7))=1,sheet3!$D$2:$D$7),0)=ROW($1:$6))))>1,"Multiple",INDEX(sheet3!D$2:D$7,MATCH(1,(sheet3!$B$2:$B$7=sheet4!H7)*ISNUMBER(SEARCH(sheet4!G7,sheet3!$C$2:$C$7)),0)))
This formula seems to work in my sheet. The formula has to be entered with ctrl+shift+enter if one doesn't work with Office365 or 2021. Do you happen to work with Office365 or 2021? I think with the help of the UNIQUE and FILTER formula it would be a lot easier to do this.
- OliverScheurichGold Contributor
=IFERROR(INDEX(sheet3!D$2:D$7,SMALL(IF((sheet3!$B$2:$B$7=sheet2!$G$5)*ISNUMBER(SEARCH(sheet2!$F$5,sheet3!$C$2:$C$7)),ROW(sheet3!$D$2:$D$7)-1),ROW(sheet2!1:1))),"")
Does this formula return your expected result? Enter the formula with ctrl+shift+enter if you don't work with Office365 or 2021.
- Chaitanya_PalleyCopper Contributor
Hi OliverScheurich , thanks for the response. I used your formula, it still seems to work the same way as vlookup. It is bringing the first instance value when I select "FI". The formula should some way find that "FI" is more than once uniquely and let us to return "Multiple" as there are more than one number values for country "FI"(234 and 567).
- OliverScheurichGold Contributor
I assume that the formula is only entered in cell H4. You can drag the formula down to cell H10 and across the range H4:I10. In my sample sheet you can see that the formula returns all values for number and local language according to the country code and the ID.