16 August 2023
Combining multiple fields together into a single field is known as concatenation in Tableau. This allows you to merge text from different columns, blend data sources, and create new calculated fields. Concatenation is a handy technique for data preparation and shaping that enables more customised analysis. This topic is taught on Tableau training courses including courses run by JBI Training.
In this guide, you'll learn what concatenation is, why it's useful, and how to concatenate fields in Tableau using both calculated fields and table calculations.
Field concatenation joins two or more text fields together to form a new single field. For example, you may want to combine first and last name columns into a full name column. Or concatenate a product code and description into one field.
This merging of fields enables new insights and customizations:
Tableau provides two primary methods for concatenating fields:
Next let's look at each of these Tableau concatenation approaches.
Calculated fields allow you to create new fields by defining a formula. This is the most common way to concatenate in Tableau.
To concatenate with a calculated field:
//Concatenate format CONCATENATE([First Name], ' ', [Last Name]) //Concat format Concat([First Name], [Last Name])
Let's look at some examples.
A common use case is combining first and last name into a full name:
CONCATENATE([First Name],' ',[Last Name])
This joins the first name, a space separator, and last name text fields.
You can use an IF statement to check for null values:
IF [First Name] = NULL THEN [Last Name] ELSE CONCATENATE([First Name],' ',[Last Name]) END
This displays just last name if first name is null.
Joins allow concatenating fields from different data sources:
CONCATENATE([Orders].[Product ID],': ',[Products].[Product Name])
That merges the ID from the Orders table and name from Products table.
The key is to understand Tableau's calculated field syntax and functions. With that foundation you can concatenate as needed for your analysis.
Table calculations offer a more advanced, dynamic way to concatenate fields in Tableau.
Instead of a predefined calculated field, table calculations run on-the-fly based on the vis context. That allows:
To use a table calculation for concatenation:
Let's walk through an example.
We'll create a table calc to concatenate product name and category:
CONCATENATE([Product Name]," - ",[Product Category])
This will now dynamically concatenate product name and category in visualizations.
The power comes from applying filters to control the concatenation context:
For example, we can EXCLUDE product name from the concat context to keep it fixed:
This lets us build calculated tooltips and labels using context-aware concatenation.
Table calculations open up many possibilities through flexible, dynamic field merging.
Let's briefly cover some more advanced topics to take your Tableau concatenation skills further:
IF [Region] = 'West' THEN CONCATENATE([Product Code],'-W') END
With the basics covered, you can combine, shape, and wrangle data in Tableau using concatenation techniques. The key is understanding how to leverage calculated fields and table calculations to merge fields dynamically.
Let me know if you have any other questions!
Use the Concatenate() function in a calculated field. For example:
CONCATENATE([First Name], [Last Name])
They are identical functions in Tableau that merge text fields together. Concatenate() is the official name but Concat() works the same.
Yes, by using a calculated field with a join. The formula can reference columns from multiple joined tables.
Main reasons are to blend data, build descriptive labels, create hierarchies, prepare data for further analysis, and combine values dynamically.
Use an IF statement in the calculated field to check the parameter value. Then output the desired concatenation string accordingly.
Full names, addresses, stock symbols, catalog numbers, combined ratings, dynamic tooltips, and more. Get creative!