Tableau Concatenate Strings

In Tableau, string concatenation is the process of combining (concatenating) two string fields or columns to create a new field (calculated) to ease the data analysis. While preparing the data to Analyze, string concatenation is the most common operation one will perform. For instance, contact First and Last Name to get the Customer’s Full Name.

Like any other programming language, you can use the + sign to join two more strings. However, unlike others, you must use the Tableau string concatenation to create a more meaningful field.

This article shows how to concatenate strings in Tableau, concatenate strings and dates, and concat strings and integers (numbers) with examples.

Tableau Concatenate Strings Syntax

The syntax of the Tableau concatenate strings is as shown below.

String1 + String2 +…… + StringN

As the above syntax shows, we used the + sign to combine multiple strings. Remember, the Tableau result will become NULL if you concatenate the string with NULL. For instance, “Tutorial” + ” ” + “Gateway” + NULL = NULL. So, please be careful while working with NULLS. Otherwise, use IFNULL to replace NULLS with default names.

To demonstrate the Tableau String concatenation, we use the Employee table. First, we must create a calculated Field to write an expression. To do this, right-click the Measures shelf empty space to select the Create Calculated Field.. option.

Tableau Concatenate Strings Example

In this example, we need the Employee’s Full Name. So, let me name the field as the FullName and write the below-shown expression. Here, we used the + Assignment operator between the FirstName and LastName to get the full name of an employee.

[First Name] + [Last Name]
Write the Expression to Join First Name and last Name using + sign

Next, let me add that FullName calculated field between the table’s LastName and Occupation. From the screenshot below, you can see the full name, but there is no space between the First and Last. Here, to stand out in the column, we formatted the text. To do so, right-click any cell and click the format or use the format menu. Please refer to the other Functions articles in Tableau.

Tableau Concatenate two Strings

Within the Measure Values shelf, click the down arrow beside the FullName field and choose the Edit Calculated Field option, which will open the below window. Next, add a space within the double quotes and click the Apply button to see the change. You can also use the SPACE() function.

[First Name] + " " + [Last Name]
Join First Name and last name with Spaces

In Tableau, the concatenation of strings is not limited to two; you can contact more columns, and the separator can be a number, space, column, hyphen, etc. In this example, we will construct an employee’s details by concatenating the first and last Name, Education, and Occupation. If you see the expression, we used space, hyphen, and underscore between the columns.

[First Name] + " " + [Last Name] + "-" + [Education] + "_" + [Occupation]

Add the Emp ID, Employees field, Hire Date, Income, and Sales to the table.

Tableau Concatenate more than two Strings (four)

Concatenation of String and Date in Tableau

There won’t be any problem with concat strings. However, it will throw an error if you want to concatenate the string and date. So, we must convert the Date field using the Tableau STR() function and then use the + operator to concatenate String and Date.

[First Name] + " " + [Last Name] + " Joined on " + STR([Hire Date])

Please add the NameDate field to the Table.

Concatenation of String and Date in Tableau

Concatenation of String and Number in Tableau

As we said earlier, you must use the STR() function to convert any field to a string to perform the Concatenation of String and Number (integer). So, please wrap the Income column inside the STR() function. In other words, use Income as the STR() function argument.

[Occupation] + " - " + STR([Income])

Let me add the concat field to the table report.

Concatenation of String and Number in Tableau

Concatenate Strings in Tableau Charts

All the above examples work on the table. However, the real power comes when you use the string concatenation on charts. To demonstrate the same, let me add the Product Category, Product Subcategory, and Color from the Adventure Works Database to the Column Shelf and the Sales Amount to the Rows Shelf. If you observe the screenshot below, the bar chart report looks odd, making it difficult to understand the data.

Bar Chart

What if we use the Tableau string concatenation to join the Category, Subcategory, and Color? It makes sense. So, create a calculated Product Details field and write the expression below.

[English Product Category Name] + " - " + [English Product Subcategory Name] + " > " + [Color]

Remove those three items from the Rows shelf and add the Product Details to the Bar Chart shelf.

Tableau Concatenate Strings in Bar Chart