A couple of weeks ago I published a video where I showed how to count unique values. At the start of that video I had a screenshot that displayed the names of the cities for each country in a single cell and a count of the number of items in the cell.

Since I published the video I’ve had a couple of people emailing me asking how I generated the cities-in-a-single-cell and the count of items in the cell.

This week’s YouTube video provides the answers.

The formulas I use in the tutorial:

=TEXTJOIN(",",TRUE,UNIQUE(FILTER($B$2:$B$13,$C$2:$C$13=F2)))

=COUNTA(TEXTSPLIT(J2,", "))

TEXTJOIN

J2 contains the TEXTJOIN function. This combines into a single string the result of the UNIQUE(FILTER($B$2:$B$13,$C$2:$C$13=F2)) function.

The UNIQUE/FILTER function generates a unique list of cities (from column B) where the country (column C) matches France (F2).

The first argument of the TEXTJOIN function is the separator string (known as a delimiter) which in this example is comma-space, hence each city having a comma and space between them.

The second argument of the TEXTJOIN function is TRUE which means ignore any empty cells in the range to be combined (column B in this example).

TEXTJOIN is available in Excel 2016 and later. UNIQUE and FILTER are available in Excel 365 and Excel 2021 and later

COUNTA and TEXTSPLIT

H2 counts the number of items in J2. This is done by combining TEXTSPLIT and COUNTA.

TEXTSPLIT is used to split the contents of a single cell based on a delimiter which in this example is comma-space. What this function is actually doing is splitting the text string in column J into multiple items based on comma-space but unlike Text-to-Columns it isn’t physically storing the “broken-apart” string anywhere.

COUNTA counts the number of items generated by TEXTSPLIT.

COUNTA is available in all versions of Excel. TEXTSPLIT is available in Excel 365 and Excel 2021 and later

Download a copy of the file used in this video: https://share.zight.com/RBuRm1rg