Extract Items Under a Category from the Same Column in Excel

Published on

In Excel, you can use a combination of the XLOOKUP and DROP functions to extract items under a specified category from the same column.

Unlike databases, Excel is flexible and allows you to enter data in various formats. Sometimes, we may have categories and their corresponding items in a single column, with prices or other details in another column. Here’s an example of such a dataset:

OPTIONSPRICE
Flooring Options
Engineered Timber$2,500
Laminate$1,000
Wall Finishes
Paint$500
Wallpaper$1,500
Roofing Materials
Colorbond Steel$3,000
Terracotta Tiles$6,000
Door Options
Standard Door$800
Sliding Door$1,500
Lighting Options
LED Lights$300
Pendant Lights$1,000
Kitchen Cabinets
Laminate$2,000
Veneer$3,500

Objective:

Suppose you want to extract all items under the category “Kitchen Cabinets”. The items are:

  • Laminate – $2,000
  • Veneer – $3,500

Here’s how you can do that:

Step 1: Create a List of Categories

Let’s assume the data is in range A1:B19.

First, create a list of categories in column D. Based on the sample data, you would enter the following values in D1:D6:

  • Flooring Options
  • Wall Finishes
  • Roofing Materials
  • Door Options
  • Lighting Options
  • Kitchen Cabinets

Step 2: Specify the End of the List

To mark the end of the last category, enter any character below the last non-empty cell in column A (e.g., in cell A20). This character, such as an underscore (_), will act as a placeholder to signal the end of the item list for the final category. It helps to clearly define where the category items end, especially when working with flexible data in Excel.

Added underscore to mark the end of items in the last category

Why is this important?

The items under each category fall between two category names. For the last category (e.g., “Kitchen Cabinets”), the boundary is unclear unless we specify this placeholder.

Similarly, enter the same character below the category list in column D—in this case, in cell D7.

Step 3: Specifying the Category and Finding the Next Category

In cell F1, for example, enter the category “Wall Finishes”.

We want to extract all the items under “Wall Finishes” in the table that spans across columns A and B.

Now, in cell F2, enter the following formula:

=OFFSET(XLOOKUP(F1, D1:D6, D1:D6), 1, 0)

This formula looks for the category in F1 in the list in D1:D6 and returns the corresponding value. The OFFSET function then moves one row down, pointing to the next category.

Step 4: Formula to Extract Items Under a Category from the Same Column

Now, to extract the items, use the following formula in cell H1:

=DROP(
   DROP(
      XLOOKUP(F1, A2:A20, A2:A20):XLOOKUP(F2, A2:A20, B2:B20), 
      1
   ), 
   -1
)
Example of extracting items under a category from the same column in Excel

How This Formula Works:

There are two XLOOKUP functions and two DROP functions at play here:

  • XLOOKUP(F1, A2:A20, A2:A20): This looks for the category in F1 (e.g., “Wall Finishes”) within the range A2:A20 and returns the corresponding value from the same column (A2:A20).
  • XLOOKUP(F2, A2:A20, B2:B20): This looks for the next category in F2 within the same column range (A2:A20) and returns the corresponding value from column B2:B20.

The colon (:) between the two XLOOKUP functions creates a range that includes all the values between the first and second XLOOKUP results.

  • DROP(..., 1): Removes the first row in the range (which corresponds to the category name in F1).
  • DROP(DROP(..., 1), -1): Removes the last row in the range (which corresponds to the next category’s name).

Notes:

  • This method extracts items under a specified category in the same column. The example above uses two columns (A and B). If your data spans more columns (e.g., columns A:D), adjust the second XLOOKUP function’s range accordingly. For example, change B2:B20 to D2:D20.
Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

How to Create a Searchable Table in Excel Using the FILTER Function

Finding specific records, or rows containing the required information, is straightforward in Excel using...

Time Sequences in Excel by Minute, Hour, or Second Increments

Creating time sequences, whether by hour, minute, or second increments in Excel, can be...

Finding Most Frequent Text in Excel with Dynamic Array Formulas

Looking to identify the most frequently occurring text in Excel? You can do this...

Hierarchical Numbering Sequences in Excel

Creating hierarchical numbering sequences in an Excel spreadsheet can significantly improve the way you...

More like this

How to Create a Searchable Table in Excel Using the FILTER Function

Finding specific records, or rows containing the required information, is straightforward in Excel using...

Time Sequences in Excel by Minute, Hour, or Second Increments

Creating time sequences, whether by hour, minute, or second increments in Excel, can be...

Finding Most Frequent Text in Excel with Dynamic Array Formulas

Looking to identify the most frequently occurring text in Excel? You can do this...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.