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.

How to Generate Semimonthly Dates in Google Sheets

If you need to generate semimonthly sequential dates in Google Sheets, you can do...

How to Make Just One Page Landscape in Google Docs

Sometimes, you may need to include a wide table, an organizational chart, or a...

Google Sheets: Get the Last Row with Any Data Across Multiple Columns

It’s common to have several empty rows at the bottom of a Google Sheet,...

How to Calculate Digital Root in Google Sheets

The digital root is the single-digit value you get by repeatedly summing the digits...

More like this

How to Generate Semimonthly Dates in Google Sheets

If you need to generate semimonthly sequential dates in Google Sheets, you can do...

Google Sheets: Get the Last Row with Any Data Across Multiple Columns

It’s common to have several empty rows at the bottom of a Google Sheet,...

How to Calculate Digital Root in Google Sheets

The digital root is the single-digit value you get by repeatedly summing the digits...

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.