Tableau allows you to concatenate two or more string (text) fields into one by using a calculated field.
You only need to add the unary plus +
operator between your two string fields as shown below:
[string1] + [string2]
For example, in the screenshot below we have the City
and Item
dimension variables displayed as table rows:
To concatenate the two dimension variables, create a Calculated Field with the following formula:
[City] + [Item]
The resulting Calculated Field will be as shown below:
Note that there is no space between the City
and Item
values in the City - Item
field above.
You can add any kind of string enclosed in double-quotes between the variables like this:
[City] + " " + [Item]
The above formula will add a single whitespace between the field values.
Concatenate multiple fields with non-string values
When you want to concatenate non-string variables, you need to use the STR()
function to gain the string representation of your variable values.
For example, you can concatenate City
and Total Sales
variables as follows:
[City] + "_" + STR([Total Sales])
The STR()
function will convert the values of the Total Sales
variable into a string so that it can be concatenated with the City
values.
You can also do this with other types, like the Order Date
variable which is a date type:
[City] +"_"+
STR(DATEPART('month', [Order Date])) +"_"+
STR(DATEPART('year', [Order Date]))
The DATEPART()
function is used to extract a specific part of the Order Date
variable.
In the case of the example above, the month
and year
part of the variable values are extracted.
The result of these calculated fields are as shown below:
You can view and download the Workbook for this tutorial here:
And that’s how you concatenate fields using Tableau.
You also learned how to concatenate non-string values with the help of the STR()
function. Nice work! 😉