Skip to main content
HomeAbout TableauLearn Tableau

How to Concatenate in Tableau Tutorial

Learn to concatenate multiple strings and non-string fields with this visual guide.
Jun 2022  · 7 min read

Image by Author

What is Concatenation?

The concept of concatenation is about combining multiple fields to create a new one to serve a particular context-based purpose. In Tableau, two or more string fields are combined to create another field. 

For example:

In Tableau, you can create a calculated field and combine multiple string fields using the “+” mark.

string_field_1 + string_field_2 + string_field_3...+ string_field_n

You can also combine multiple string fields with non-string fields by using the string conversion function.

In this tutorial, we will learn about non-concatenate examples and follow a step-by-step guide to concatenate multiple strings and non-string fields using Tableau functions. 

Non-Concatenate Example

To initiate the workspace, we need to connect the data source in Tableau Public (Desktop). In our case, it is a CSV file containing power consumption data in India (2019-2020). You can download the file from Kaggle here. The `long_data_.csv` file consists of Dates, Regions, States, Latitude, Longitude, and Usage(MWh) columns. 

In the next step, we pick and drop Region and States fields to the Columns shelf. Similarly, we pick and drop the Usage field to the Row shelf, as shown below.

This results in a sum of power usage per state bar chart separated by regions.

Non-Concatenate Table in TableauNon-Concatenate Tableau Worksheet Example

How to Concatenate in Tableau?

If we add multiple fields to the Columns shelf, the results will be chaos. You will see numerous separators dividing the bar chart into smaller chunks. We can avoid this by concatenating multiple fields into one. 

To join fields, we need to create a new calculated field by clicking on a small, downward-pointing arrow in the Data tab, or we can right-click anywhere in the Data tab to access the option. 

Tableau Data Tab

After clicking “Create Calculated Field”, the popup window will appear where you can rename the field to “Combined Region and State”. 

Combined Region and State

To add a string field, you can pick and drop the field into the input box, or you can type the field name in square brackets. In our case, we will pick and drop the Region field into the input box that will show as `[Region]`. 

Tableau Combined Region and State 2

After that, we add a field separator using the “+” mark. Make sure your separator is in double quotation marks. 

Why are we adding separators? To make sure our field values are readable.

With Separator

Without Separator

WR_Maharashtra_Mumbai

WRMaharashtraMumbai

Combining Regions and States in Tableau

Next, we will add the States field using the “+” mark and type the field name in square brackets, as shown below. 

Combining Regions and States in Tableau 2

Combining two fields does not prompt the error, so we are going to click on the “OK” button that will add a new discrete field to the Data tab. 

In the next step, we are going to plot a bar chart using the newly created fields “Combined Region and State” and “Usage”. 

As you can observe, we have successfully concatenated two fields into one. The bar chart shows the combined Region with States name. 

Tableau Bar Chart with Combined Fields

To make our chart more presentable, we can customize it by adding a title, changing the colors and orientation, and sorting values in descending order. To learn more about customizing charts, check out our tutorial on how to create a dashboard in Tableau.

Within the WR region, Maharashtra state has the highest power consumption from the year 2019 to 2020. 

Tableau Bar Chart

If you are a complete beginner and this tutorial seems overwhelming, then check out DataCamp’s Tableau Resources. The resources tab will answer all of your queries related to Tableau and business intelligence careers.  

How to Concatenate String with Non-string Values?

Concatenating a string with a non-string field will prompt an error, as you cannot add numerical values to string values. When we attempt to add Date with States and Region, the error following error is prompted: “Can’t add string and datetime values”.

Tableau Concatenate Add Error Screenshot

To resolve this issue, we will convert the datetime value to a string using the `STR` function. 

Correcting a String Error in Tableau

Add the Dates field within the `STR` function using round brackets, as shown below. After resolving the issues, we click on “OK” to add a new discrete field with Dates that will show in the Data tab. 

Combining Strings in Tableau Screenshot

To create a bar chart, we move the newly created field to Columns and Usage to Rows shelf. Each bar is now represented by power consumption per Region, State, and Date

Customizing a Bar Chart in Tableau

To make it presentable we will customize the title, colors, and orientation. 

As we can observe, on July 12th, 2019, the region of WR and the state of Maharashtra had the highest power consumption. 

Tableau Bar Chart

The non-concatenate example is divided by Regions, States, and Years. It is moderately hard to understand the line chart, and you have to scroll down hundreds of values to understand the complete picture. Whereas, in concatenate examples, things are straightforward and each bar represents the combined values of three fields. It is much easier to understand the whole picture.

Tableau Concatenate vs. Non-Concatenate

Comparison between non-concatenate and concatenate

Conclusion

Tableau is more than a visual analytical tool. It provides you the ability to use arithmetic and statistical functions to augment data fields. You can use this function to concatenate multiple fields to represent the data in a simpler format. 

In this tutorial, we have learned about concatenating functionality and how to combine multiple string and non-string values. If you are new to Tableau, then read the Tableau for Beginners tutorial.

If you are interested in learning more about Tableau functionalities, then complete all five courses from the Tableau Fundamentals skill track. These courses will teach you the basics of Tableau functionalities, data analysis, creating a dashboard, connecting multiple data sources, and building solutions to assist businesses. 

Topics

Tableau Courses at DataCamp 

Course

Introduction to Tableau

6 hr
207.9K
Start your Tableau journey with our Introduction to Tableau course. Discover Tableau basics such as its features and dashboards.
See DetailsRight Arrow
Start Course
See MoreRight Arrow
Related

6 Tableau Projects to Help Develop Your Skills

Explore our list of Tableau projects for beginner and intermediate learners across different industries and use cases.
Jess Ahmet's photo

Jess Ahmet

6 min

11 Data Visualization Techniques for Every Use-Case with Examples

Discover the most popular analyses, techniques and tools to master the art of data visualization wizard
Javier Canales Luna's photo

Javier Canales Luna

16 min

Your Guide to Tableau Certifications: Certification Levels, Costs, and How to Pass Them

Unlock Tableau certification success! Explore certification levels, costs, and expert strategies to pass. Start your journey to becoming a Tableau pro today.
Adel Nehme's photo

Adel Nehme

15 min

Data Storytelling and Visualization with Lea Pica from Present Beyond Measure

Richie and Lea cover the full picture of data presentation, how to understand your audience, leverage hollywood storytelling and much more.
Richie Cotton's photo

Richie Cotton

71 min

Visualizing Data in Excel

Learn about Excel's various data visualization options that can help you analyze and interpret your data.
Jess Ahmet's photo

Jess Ahmet

12 min

Types of Data Plots and How to Create Them in Python

Explore various types of data plots—from the most common to advanced and unconventional ones—what they show, when to use them, when to avoid them, and how to create and customize them in Python.
Elena Kosourova's photo

Elena Kosourova

21 min

See MoreSee More