Split Values by Category into Two Columns in Google Sheets

It’s common to come across comma-separated lists that need to be organized and categorized for better readability and analysis. For example, you may have a list of items—like fruits or vegetables—stored as a comma-separated string in one column, with a corresponding category label in another.

To make this data more manageable, you can split values by category in Google Sheets and lay them out into two clean columns: one for the category and one for each individual item.

In this guide, you’ll learn how to split values by category into two columns in Google Sheets, transforming your comma-separated lists into a structured format that’s easier to analyze and filter.

Formula to Split Values by Category into Two Columns in Google Sheets

Here’s a formula that splits text into columns and categorizes the results in Google Sheets:

=LET(
   data, ARRAYFORMULA(SPLIT(FLATTEN(cat&"|"&SPLIT(items, ", ", FALSE)), "|")), 
   SORT(FILTER(data, CHOOSECOLS(data, 2)<>""))
)

Replace items with the range containing the comma-separated values, and cat with the corresponding category label range.

Features of This Formula

  • No LAMBDA required — Resource friendly
  • Array formula — processes the entire dataset at once; no need to drag down
  • Sorted output — categories appear in ascending order
    • If you want to keep the original row order, replace: SORT(FILTER(data, CHOOSECOLS(data, 2) <> "")) with: FILTER(data, CHOOSECOLS(data, 2) <> "")

How to Split and Categorize Comma-Separated Data in Google Sheets

In the example below, column A contains category labels (e.g., Fruits, Vegetables) and column B contains the corresponding comma-separated items.

Google Sheets example: split comma-separated values by category into two columns

Split to Column and Categorize Multiple Rows of Values

Paste the following formula in cell D1:

=LET(
   data, ARRAYFORMULA(SPLIT(FLATTEN(A1:A&"|"&SPLIT(B1:B, ", ", FALSE)), "|")), 
   SORT(FILTER(data, CHOOSECOLS(data, 2)<>""))
)

Formula Logic Explained

Here’s how the formula works to split values by category in Google Sheets:

  • SPLIT(B1:B, ", ", FALSE) – splits the comma-separated values using ", " as the delimiter.
    If your values are just comma-separated (no space), use "," instead.
  • A1:A&"|"& ... – combines each category with each corresponding item using a pipe (|) as a delimiter.
  • FLATTEN(...) – flattens the combined results into a single column like this:
Fruits|Apple
Fruits|Mango
Fruits|Orange
Fruits|Banana
Fruits|
Vegetables|Carrot
Vegetables|Asparagus
Vegetables|Cauliflower
Vegetables|Eggplant
Vegetables|Green Pepper
  • SPLIT(..., "|") – separates each string into two columns: Category and Item.
  • FILTER(data, CHOOSECOLS(data, 2) <> "") – removes any rows where the item column is blank.
  • SORT(...) – sorts the final result by category.

And that’s how you split values by category into two columns in Google Sheets—clean, dynamic, and fully formula-based!

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Mode of Comma-Separated Numbers in Excel (Dynamic Array)

There is no dedicated function in Excel to directly find the mode of comma-separated...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

Count Consecutive Workday Absences in Google Sheets

This tutorial offers a powerful formula-based solution to count consecutive workday absences in Google...

More like this

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

Count Consecutive Workday Absences in Google Sheets

This tutorial offers a powerful formula-based solution to count consecutive workday absences in Google...

8 COMMENTS

    • Hi, Federico Finati,

      Thanks for the screenshot. I could understand you want the opposite of the problem attended in this tutorial.

      Sample data in A1:B
      A | B
      Item | Category
      Fruit | Orange
      Fruit | Lemon
      Fruit | Banana
      Vegetable | Spinach
      Vegetable | Cucumber

      As per this sample, you can use these formulas.

      D2:

      =unique(A2:A)

      E2:

      =byrow(unique(A2:A),lambda(r, textjoin(", ",true,filter(B2:B,A2:A=r))))

      N.B.:- Byrow is a new function. You can find the related tutorial in my Function Guide.

  1. Just what I needed!

    You can discard the QUERY() call if you swap around the concatenation inside the regexp replace so the category goes first:

    =ArrayFormula(TRIM(split(transpose(split(textjoin("^",1,if(len(B1:B),
    REGEXREPLACE(","&B1:B,",",","&A1:A&"^"),)),",")),"^")))

    Instead of
    Apple, Mango, Orange, Banana,
    Apple^Fruits, Mango^Fruits, Orange^Fruits, Banana^Fruits,

    it’s now

    ,Apple, Mango, Orange, Banana
    ,Fruits^Apple, Fruits^Mango, Fruits^Orange, Fruits^Banana

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.