Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Excel - hierarchical lookup columns

Posted on 2014-08-01
Medium Priority
Last Modified: 2016-11-23
What are the best approaches to accomplish a hierarchical lookup in excel.
What I mean is, first find the matching main category and then based on that find all subcategory matches that belong to the main category.

So for example, suppose I have a some rows of text in Worksheet1 Col A each of which has embedded within the text a brand name and a product name. e.g. "Dell laptop computers are great" or " HP laserjet printers print fast". Dell and HP would be the main categories and computer and printer would be subcategories.

And suppose I have some lookup lists in another worksheet, Worksheet2.
Worksheet2 Col A holds brand names (unique list no repeating values e.g. Dell, HP, Apple). Worksheet2 Cols B and C hold product category in Col B and product name in Col C - brand names would be a repeating field, product name would be unique and the combination of the two would be unique and tie a product to a brand) e.g. Dell Laptop, Dell Desktop, Dell Tablet, HP Laserjet, HP Inkjet, HP Thermal

Back on Worksheet1, I want to search Worksheet 1 Col A for the occurrence of a matching product category from Worksheet2 Col A and display that in Worksheet1 Col B. So if the text says "Dell computers" then Col B would say Dell.

Then in Worksheet1 Col C I want to display a dropdown list of all matching products belonging to the product category in Worksheet1 Col B (the result of the search) so that the correct product can be manually selected from the drop down. So if the text says "Dell laptop computers are great" then Col B would say Dell and the dropdown in Col C would show all the products for Dell (e.g. Desktop, Laptop, Tablet, etc.) and the user will select the correct product.

Which formulas should be used where e.g. search, index, Vlookup, etc.

I have attached a file set up with the columns described above.

Thanks in advance.
Question by:bobinorlando
  • 2
LVL 27

Accepted Solution

Glenn Ray earned 2000 total points
ID: 40235478
You can achieve this with:
1) a formula to determine the key word (brand) in the phrase, and
2) a named range that uses an OFFSET function to return the valid product types based on the brand found (if any)

I've modified your workbook by removing the descriptor rows, so now, on Sheet1, the header row is
A1: Text
B1: Brand
C1: Product

I've then taken your two data lists on Sheet2 and assigned them to two Excel Tables:  "Brands" (col A) and "BrProducts" (col B:C).  This will be helpful in keeping your functions dynamic if you add/remove brands or products in the future.

1) In cell B2, you insert the following array formula (entered with [Ctrl]+[Shift]+[Enter]) to display a valid brand name that may appear in the text in A2:

2) Using the Name Manager, I created a named range called "PrLookup" that has the following formula in the "Refers to:" field:
This determines the range on Sheet2 in the BrProducts table for any valid products for the displayed brand in column B
Named Range used for data validationThen, in cell C2, I added a Data Validation rule that references PrLookup for the valid list of values and copied that cell down.
data validation set up
I also added some other test brands and text to test.  I initially questioned why - if the text statement may actually describe a product type - you would ask a user to select the product.  Then I realized that this may be a teaching exercise to instruct persons on interpreting sentence structure.  Is that correct?


Author Comment

ID: 40235564
Thanks Glenn. Actually no, the instant file is merely a template. Other data will be substituted for the simple examples I provided and because the number of brands and products will be quite long - thousands of products of which 40-50 may roll up to a single brand -- and the text is much more complex that we are searching so we're going to manually match the names rather than trying to match them programmatically. Code works great when matching a brand name, but the text has many inconsistencies in the way product names are stated and will produce too many inaccurate matches so for that task a person is more accurate, thus the drop downs to at least narrow down what they have to review but enable them to easily pick off the right match and keep moving.
LVL 27

Expert Comment

by:Glenn Ray
ID: 40235616
Okay; interesting to hear more about how this will be applied.  Go ahead and experiment by expanding the existing tables and adding some sample text on the first sheet that more-closely resembles your actual data.  Let me know how it works.


Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question