Partial match lookup

iyeung26

New Member
Joined
Aug 28, 2017
Messages
3
Hi all - first post, would appreciate some help. I have an extract from SharePoint on Excel and I want to do a lookup against my Excel mapping table.

The table I have in the spreadsheet is the "List from SharePoint" where I have a string with lots of # and ;s, I want to use that string and lookup against a table and count how many vegetables/fruit there are.

I would like the outcome of the lookup to be the numbers in orange below, is this feasible? I prefer to use the mapping table as my list of vegetables & fruit are quite long :) Thanks.

[TABLE="width: 509"]
<tbody>[TR]
[TD]List from SharePoint[/TD]
[TD]Lookup output: Fruit[/TD]
[TD]Lookup output: Vegetable[/TD]
[/TR]
[TR]
[TD];#Apple;#Pear;#Carrot;#[/TD]
[TD]2[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD];#Apple;#Pear;#Tomatoes;#Carrot;#[/TD]
[TD]2[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Mapping table[/TD]
[TD]Type[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Apple[/TD]
[TD]Fruit[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Pear[/TD]
[TD]Fruit[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Carrot[/TD]
[TD]Vegetable[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Tomatoes[/TD]
[TD]Vegetable[/TD]
[TD][/TD]
[/TR]
</tbody><colgroup><col><col span="2"></colgroup>[/TABLE]
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Welcome to the MrExcel board!

Firstly a newbie tip: Even if you are in a hurry, don't bump your post so quickly. At the top of the forum is a "Zero Reply Posts" and many of the experienced helpers go there first to look for questions that need answering. As soon as you replied to your own thread, it no longer appeared in that list, so you immediately tend to get less 'lookers' & potential helpers. If you haven't done so yet, I suggest that you have a good look at the Forum Rules and the Forum Use Guidelines.

Now for your problem. Does this do what you want? This is an array formula so should be entered without the {} but confirmed with Ctrl+Shift+Enter, not just Enter. If confirmed correctly, Excel will insert the {}. The formula can then be copied across and down.

Excel Workbook
ABC
1List from SharePointFruitVegetable
2;#Apple;#Pear;#Carrot;#21
3;#Apple;#Pear;#Tomatoes;#Carrot;#22
4
5
6
7Mapping tableType
8AppleFruit
9PearFruit
10CarrotVegetable
11TomatoesVegetable
Count
 
Last edited:
Upvote 0
[TABLE="class: grid, width: 478"]
<tbody>[TR]
[TD]List from SharePoint[/TD]
[TD]Fruit[/TD]
[TD]Vegetable[/TD]
[/TR]
[TR]
[TD];#Apple;#Pear;#Carrot;#[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD];#Apple;#Pear;#Tomatoes;#Carrot;#[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Mapping table[/TD]
[TD]Type[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Apple[/TD]
[TD]Fruit[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Pear[/TD]
[TD]Fruit[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Carrot[/TD]
[TD]Vegetable[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Tomatoes[/TD]
[TD]Vegetable[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

In B2 control+shift+enter, not just enter, copy across, and down:

=SUM(IF(ISNUMBER(SEARCH($A$6:$A$9,$A2)),IF($B$6:$B$9=B$1,1)))
 
Upvote 0
In B2 control+shift+enter, not just enter, copy across, and down:

=SUM(IF(ISNUMBER(SEARCH($A$6:$A$9,$A2)),IF($B$6:$B$9=B$1,1)))
Hi Aladin

Note that is not robust against fruits and vegetables that share a common word. For example, the mapping table already has the Fruit "Apple", but if it also included the Vegetable "Ground Apple" (from Peru) then your formula would give an incorrect count for fruit for the string ";#Ground Apple;#Pear;#Carrot;#"
 
Last edited:
Upvote 0
Hi Aladin

Note that is not robust against fruits and vegetables that share a common word. For example, the mapping table already has the Fruit "Apple", but if it also included the Vegetable "Ground Apple" (from Peru) then your formula would give an incorrect count for fruit for the string ";#Ground Apple;#Pear;#Carrot;#"

Thanks. That's easily corrected for...

=SUM(IF(ISNUMBER(SEARCH(";#"&$A$6:$A$9&";#",SUBSTITUTE($A2," ",""))),IF($B$6:$B$9=B$1,1)))
 
Upvote 0
That's easily corrected for...

=SUM(IF(ISNUMBER(SEARCH(";#"&$A$6:$A$9&";#",SUBSTITUTE($A2," ",""))),IF($B$6:$B$9=B$1,1)))
That still fails for the example I gave as the SUBSTITUTE then naturally fails to match GroundApple with Ground Apple.
I think with your approach, the following should suffice

{=SUM(IF(ISNUMBER(SEARCH("#"&$A$6:$A$9&";",$A2)),IF($B$6:$B$9=B$1,1)))}
 
Upvote 0
That still fails for the example I gave as the SUBSTITUTE then naturally fails to match GroundApple with Ground Apple.
I think with your approach, the following should suffice

{=SUM(IF(ISNUMBER(SEARCH("#"&$A$6:$A$9&";",$A2)),IF($B$6:$B$9=B$1,1)))}

Or...

{=SUM(IF(ISNUMBER(SEARCH(";#"&SUBSTITUTE($A$6:$A$10," ","")&";#",SUBSTITUTE($A2," ",""))),IF($B$6:$B$10=B$1,1)))}

The idea is clear and simple, although never exhaustively safe for any possible case.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top