Arte SheetsLearn. Try. Understand.

Text

Sort and deduplicate comma-separated values inside a single cell

Canonicalize messy tag strings ("urgent, billing, api, billing" -> "api, billing, urgent") using TEXTSPLIT, TRANSPOSE, UNIQUE, SORT, and TEXTJOIN.

Why canonical sorted tags prevent missed exact matches

Two CRM records tagged "billing, urgent" and "urgent, billing" mean the exact same thing, yet A2 = B2 and UNIQUE treat them as different strings.

Splitting into a vertical vector—TRANSPOSE(TEXTSPLIT(LOWER(SUBSTITUTE(A2, " ", "")), ","))—then wrapping in UNIQUE and SORT and rejoining with TEXTJOIN(", ", TRUE, ...) normalizes case, spacing, duplicates, and alphabetical order in one step.

RawTags (A)Pipeline StepNormalized Output
Urgent, billing, API, billingSplit -> Vertical -> Unique -> Sort -> Joinapi, billing, urgent

Sort and deduplicate single-word tags in a cell

Using row_delimiter = "," (3rd argument of TEXTSPLIT) or TRANSPOSE ensures UNIQUE and SORT operate down rows cleanly.

=TEXTJOIN(", ", TRUE, SORT(UNIQUE(TRANSPOSE(TEXTSPLIT(LOWER(SUBSTITUTE(A2, " ", "")), ",")))))

Sort multi-word comma phrases (preserving internal spaces)

When items contain internal spaces like "New York, Austin, Boston", split on ", " directly instead of stripping all spaces.

=TEXTJOIN(", ", TRUE, SORT(UNIQUE(TRANSPOSE(TEXTSPLIT(A2, ", ")))))

Inputs and interpretation

The first variant is for single-word tags: removing every space would merge multiword names. The second expects the exact delimiter comma followed by one space; normalize inconsistent separators first. Neither formula parses CSV quoting or commas inside values. Case folding and sort order are chosen policies and may differ with locale; retain originals if tag identity is case-sensitive.

Try the example

Use the original values or change them to test your understanding.

Further reading