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 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.

Reset SCAN by Another Column in Google Sheets and Excel

Resetting SCAN function results based on values in another column is a topic of...

How to Get the Fastest Time for Each Person in Google Sheets

Whether you’re tracking race results, event times, or any other timed activities, finding the...

Highlight the Smallest N Values in a Column in Google Sheets

Want to visually spotlight the lowest values in your data? In this tutorial, you'll...

Sort Each Row Individually in Excel Using a LAMBDA Formula

Sorting rows in Excel typically refers to rearranging entire datasets based on values in...

More like this

How to Get the Fastest Time for Each Person in Google Sheets

Whether you’re tracking race results, event times, or any other timed activities, finding the...

Highlight the Smallest N Values in a Column in Google Sheets

Want to visually spotlight the lowest values in your data? In this tutorial, you'll...

How to Sort Pie Slices in Google Sheets

To sort pie slices in a pie chart, you need to sort the data...

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.