Developers can add fixed value columns or create conditional columns in Tableau using calculated fields. We’ll explain how to create a new column to add specific values, concatenate two columns, and even create a conditional column in your dataset.
Tableau is a highly flexible platform and as such there are usually multiple ways to perform a similar task. We’ll explain two different methods for creating new columns and highlight a few of the formulas used in the most common use cases.
Let’s jump in!
Table of Contents
When to Create New Columns in Tableau
It’s somewhat rare to import data into Tableau and find that it has all of the information that you need, in the format that you need from the start. A lot of times, you will need to add new columns to combine columns or augment the data that comes into Tableau.
We recommend adding in data as one of the first parts of building a Tableau dashboard. The more data prep and data modeling you do up front will give you a clean data source to work with when creating your dashboard.
Some of the most common scenarios that require the creation of a new column include:
- Data Transformation – Cleaning, parsing, and getting data into a workable format.
- Concatenation – Combining two columns together like First Name and Last Name into a single column
- Complex Calculations – Breaking complex calculations into smaller parts for ease of use and understanding
- Conditional Logic – IF statements, similar to Excel to dynamically calculate new columns.
Of course, as you work with Tableau, you will likely find all sorts of use cases where it’s either necessary to add columns or easier in the grand scheme of your data model vs creating complex measures.
How to Create New Columns in Tableau
There are two ways to add new columns in Tableau. You can either create a new column from the Data Source View or you can create a new column from the Worksheet View. The work the same, it’s more of a matter of preference and convenience when choosing which one to use. We’ll explain both.
Creating a New Column from the Data Source View
Using the Data Source tab is our preferred way to create new columns in Tableau. It makes it easier to see beginning and ending day, and by default will show you the first 100 rows. Being able to see the beginning and end is especially helpful when concatenating or adding conditional columns.
To add a new column in Tableau right click on the top of any existing column of your dataset and select Create Calculated Field.
A new formula box will pop up for you to enter in a formula to create a new column. There are two sections to it, the top part of the box that says “Calculation1” becomes the new column header. Then the orange text section with the larger box is where you write a Tableau Formula.
Formulas can range from simple to complex, and while it’s a proprietary formula language specific to Tableau you will find many similarities with other data prep and business intelligence tools like Alteryx.
Creating a New Column from the Worksheet View
The other method to add columns in Tableau is from the worksheet view. It’s a quick convenient way to add a fast calculation without leaving the visualization that you’re working on. To launch the formula editor, right click anywhere on the data tab and select Create Calculated Field
A formula box will appear and the formula that you enter in will generate a new column when you flip back to the data source view.
Common Use Cases and Examples of Adding New Columns in Tableau
We’ll explain a few of the most common ways to create new columns in Tableau that are vital to know if you’re new to the platform or have used it for a little while.
Creating a New Column with a Fixed Value
Creating a column with a single value can be done with a formula. To create a new column with a numeric value, you just have to type in the number. When creating columns with a fixed text value, the text has to be surrounded in double quote marks, like “Hello World”
Tableau uses quotes to define text where it’s not necessary when working with numbers.
This can be especially useful if you have a fixed target like a budget number that you want to compare actual results against.
Creating a New Column to Concatenate Columns
Tableau uses the + sign to concatenate columns, where as in Excel, you would use an & sign. Column names are identified with square brackets surround them, and additional text like dashes, hyphens and spaces need to be surrounded by double quotes to designate them as text.
The follow example concatenates our Cookie Category Column with a Cookie Name Column with a dash inbetween.
A very common use case is combining a column of first and last names with a space in between for a single column that displays a full name.
Note: You will only be able to concatenate fields that are defined with text data types. If you try to concatenate a numeric data type with a string (text) data type you will likely see a column of null values signifying that the calculation was unable to be completed.
Creating a New Conditional Column
To create a conditional column in Tableau, right click on a column header and select Create Calculated Field from the Data Source tab. When a formula box appears, use the Syntax: IF, THEN , ELSE, END to define the condition that you’re checking for, then what happens if the condition is true, else what happens if the condition is false, then the word END to close out the IF statement.
The following example shows a Tableau IF statement in action. This would be similar to writing the Excel formula:
= IF (“Cookie Name” = Snickerdoodle, “Yes”, “No”)
Conditional columns are a staple of business intelligence and data analytics. The IF THEN ELSE END syntax can take a little bit of getting used to but can also be incredibly useful. For even more advanced conditional statements try using an ELSEIF formula when you have multiple conditions.
Conclusion
Tableau is a highly versatile business intelligence tool that gives you a couple of quick ways to add new columns. You can either right click on a column header in the Data Source view or you can right click on the data panel of the Report View. Either way will launch a formula builder.
New columns can be as simple as a number or text with quotes around it, to concatenating different named columns, or using a more complex IF statement to make a conditional column. The options are limitless and these are just a few of the most common formulas used when creating new columns.