CUSTOMISED
Expert-led training for your team
Dismiss
How to Concatenate in Tableau

16 August 2023

How to Concatenate in Tableau

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.

What is Field Concatenation in Tableau?

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:

  • Blend different data sources into unified fields
  • Build descriptive labels and names from multiple attributes
  • Shape data for derived calculations and visualizations
  • Create hierarchies and grouping fields like full location

Tableau provides two primary methods for concatenating fields:

  1. Calculated Fields - Create a new field using functions like Concatenate()
  2. Table Calculations - Dynamically combine values based on visualization context

Next let's look at each of these Tableau concatenation approaches.

Concatenating Fields with Calculated Fields

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:

  1. In the Data pane, click the dropdown and select "Create Calculated Field".
  2. Name the new field with something descriptive like "FullName".
  3. Write a formula using the Concatenate() or Concat() function.
//Concatenate format
CONCATENATE([First Name], ' ', [Last Name]) 

//Concat format 
Concat([First Name], [Last Name])
  1. The functions merge the text fields with any separators you specify.
  2. You can then use the new calculated field like any other field.

Key Notes

  • Enclose field names in [] brackets
  • Use single quotes for literal strings
  • Concat() and Concatenate() work the same

Let's look at some examples.

Concatenating First and Last Name

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.

Handling Null Values

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.

Concatenating Fields from Multiple Tables

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.

Dynamic Concatenation with Table Calculations

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:

  • Concatenation using fields not already joined
  • Combining values based on visualization filters
  • Flexible context-aware concatenation

To use a table calculation for concatenation:

  1. Create a new table calculation via the analytics pane.
  2. Set it to use a CONCATENATE() or Concat() formula.
  3. Configure the computation context with filters.

Let's walk through an example.

Table Calculation Setup

We'll create a table calc to concatenate product name and category:

  1. Open analytics pane and select "Add Table Calculation".
  2. Name it "Dynamic Concat".
  3. Formula: CONCATENATE([Product Name]," - ",[Product Category])
  4. Set compute using to "Table (Down)".

This will now dynamically concatenate product name and category in visualizations.

Managing Context with Filters

The power comes from applying filters to control the concatenation context:

  • FIXED - Locks field references to the originally clicked marks.
  • INCLUDE - Allows fields to vary based on marks included in vis.
  • EXCLUDE - Fixes all fields except those dropped into vis.

For example, we can EXCLUDE product name from the concat context to keep it fixed:

EXCLUDE Level of Detail Expressions - Tableau

This lets us build calculated tooltips and labels using context-aware concatenation.

Table calculations open up many possibilities through flexible, dynamic field merging.

Advanced Concatenation Techniques

Let's briefly cover some more advanced topics to take your Tableau concatenation skills further:

  • Nested Functions: Concatenate outputs of other functions for complex logic:
    CONCATENATE(CONCATENATE([First],' '),[Last])
    
  • Conditional Logic: Use IF statements to concatenate conditionally:
    IF [Region] = 'West' THEN CONCATENATE([Product Code],'-W') END  
    
  • Data Handling: Manage data types, null values, formatting, and blending.
  • Creative Applications: Build descriptive labels, visual tooltips, groups and more.

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!

Frequently Asked Questions About Concatenation in Tableau

How do I concatenate two string fields in Tableau?

Use the Concatenate() function in a calculated field. For example:

CONCATENATE([First Name], [Last Name])

What is the difference between Concat and Concatenate in Tableau?

They are identical functions in Tableau that merge text fields together. Concatenate() is the official name but Concat() works the same.

Can you concatenate columns from two tables in Tableau?

Yes, by using a calculated field with a join. The formula can reference columns from multiple joined tables.

Why use concatenation in Tableau?

Main reasons are to blend data, build descriptive labels, create hierarchies, prepare data for further analysis, and combine values dynamically.

How do I concatenate based on a parameter value in Tableau?

Use an IF statement in the calculated field to check the parameter value. Then output the desired concatenation string accordingly.

What are some common applications of concatenation in Tableau?

Full names, addresses, stock symbols, catalog numbers, combined ratings, dynamic tooltips, and more. Get creative!

If you enjoyed this guide you may find our other blog pieces useful including how to add filter in tableau dashboard and how to show top n in tableau

About the author: Daniel West
Tech Blogger & Researcher for JBI Training

CONTACT
+44 (0)20 8446 7555

[email protected]

SHARE

 

Copyright © 2024 JBI Training. All Rights Reserved.
JB International Training Ltd  -  Company Registration Number: 08458005
Registered Address: Wohl Enterprise Hub, 2B Redbourne Avenue, London, N3 2BS

Modern Slavery Statement & Corporate Policies | Terms & Conditions | Contact Us

POPULAR

Rust training course                                                                          React training course

Threat modelling training course   Python for data analysts training course

Power BI training course                                   Machine Learning training course

Spring Boot Microservices training course              Terraform training course

Kubernetes training course                                                            C++ training course

Power Automate training course                               Clean Code training course