I don’t normally blog about Excel topics outside of Power Query and Power Pivot, but I think anyone who has ever done any serious work in Excel has found how difficult it is to concatenate more than two text values (although there are plenty of blog posts like this one showing how to do it). Well, not any more – Microsoft have finally got around to addressing this problem with two new Excel functions, TEXTJOIN() and CONCAT(). The announcement, plus news of other new Excel functions and a new funnel chart type, is here:
First, the bad news: at the time of writing you’ll only be able to use these functions in Excel on the desktop if you’re using the click-to-run version of Excel 2016 that you get through an Office 365 subscription (ie the version installed through the Office 365 portal that gets updated by Microsoft automatically – probably not the same version that you’re running on your desktop if you work for a big company). It is available in Excel Online and Excel Mobile too. I guess they’ll appear in the regular, Windows-installer version of Excel 2016 in a service pack at some point in the future.
How about some examples? First of all, CONCAT() is a successor function for the old CONCATENATE() function – as far as I can see it does everything CONCATENATE() does but crucially also supports ranges as inputs as well as individual text values. So
=CONCAT("The ", "cat ", "sat ", "on ", "the ", "mat.")
Returns
The cat sat on the mat.
…but also, if you have each of your words in different cells (nb I’ve added spaces at the end of each word here), you can concatenate all the values in a range like this:
=CONCAT(B2:B7)
The TEXTJOIN() function is more flexible and I suspect will be very popular. It gives you two benefits over CONCAT():
- The ability to specify a delimiter – a character or characters (for example a comma or a space) to insert between each item of text you want to concatenate
- The ability to ignore empty values
Some examples…
First, using a space in the first parameter:
=TEXTJOIN(" ",FALSE,"The","cat","sat","on","the","mat.")
Returns once again
The cat sat on the mat.
…without having to add spaces to the end of each word, as I did with the CONCAT() example above:
And
=TEXTJOIN(",",FALSE,"The","cat","sat","on","the","mat.")
Returns
The,cat,sat,on,the,mat.
Finally, here’s an example of how TEXTJOIN() can be used with a range with the second parameter being set to TRUE to ignore empty cells in a range:
=TEXTJOIN(",", TRUE,B2:B9)
With the data in the screenshot below again returns
The,cat,sat,on,the,mat.
You can see an Excel Online worksheet with all these examples here.
