How to Create a New Column in Tableau Data Source
Need to add a custom column to your Tableau data source? Creating new columns from existing data - whether to combine a first and last name, calculate a profit margin, or group sales into categories - is a fundamental skill for moving beyond basic charts. This tutorial will walk you through the primary method for creating new columns in Tableau, using Calculated Fields, with clear, step-by-step instructions and practical examples you can use right away.
Why Create a New Column in Tableau?
Before jumping into the "how," let's quickly cover the "why." Your raw data is rarely analysis-ready. You often need to reshape it, create new metrics, or add context. Creating a new column directly in Tableau saves you from having to go back to your original spreadsheet or database every time you need a new dimension or measure.
Here are a few common scenarios where creating a new column is essential:
- Combining Data: You have separate
First NameandLast Namecolumns, but you want to display a singleFull Namefield. - Calculating Custom Metrics: Your data has
SalesandProfit, but you need to calculateProfit Ratio, a metric that doesn't exist in your original data set. - Segmenting Data: You want to categorize customers based on their purchase volume, creating a new
Customer Tiercolumn with values like "High Value," "Medium Value," and "Low Value." - Standardizing Data: You might need to clean up data, such as converting a text field to all uppercase for consistency or extracting a specific part of a string.
- Adding Conditional Logic: You want to create a column that flags orders, for example, labeling anything over $1,000 as a "Large Order" and everything else as a "Standard Order."
While you could make these changes in Excel or your database, doing it in Tableau keeps your original data source clean and makes your workbook a self-contained, reproducible source of truth.
The Easiest Method: Creating Calculated Fields
Tableau's solution for adding new columns is called a Calculated Field. A calculated field is a new field (which functions as a new column) that you create by defining a formula. This formula can use functions and operators to manipulate the data from your other fields.
Think of it as adding a formula column in a spreadsheet, but with more power and flexibility. Once you create a calculated field, it appears in your Data pane just like any other field, and you can drag and drop it into your visualizations. You can tell a calculated field apart from your original fields because it has an equals sign (=) next to its data type icon (e.g., =# for a numeric calculation, =Abc for a text calculation).
Step-by-Step Guide: How to Create Your First Calculated Field
Let's walk through creating a simple calculated field to calculate Sales Tax. Assume we have a Sales field and want to create a new column for a 7% sales tax.
Step 1: Open the Calculated Field Editor
There are a few ways to open the editor:
- In the Data pane: Right-click on any empty space within the Data pane (the left-hand sidebar) and select Create Calculated Field...
- From the top menu: Go to Analysis > Create Calculated Field...
- From an existing field: You can right-click a field you want to use in your formula (like
Sales) and navigate to Create > Calculated Field...
Step 2: Name Your New Column
The calculation editor box will pop up. The first thing you should do is replace the default name, like Calculation1, with a descriptive name for your new column. Clear naming is crucial for keeping your workbook organized, especially as your analysis gets more complex. Let's name this one Sales Tax.
Step 3: Write Your Formula
This is where you define the logic for your new column. In the large white text box, you'll enter your formula. You can type field names directly, and Tableau will suggest auto-completions. Field names are always wrapped in square brackets, like [Sales].
For our sales tax example, the formula is simple:
[Sales] * 0.07As you type, notice the function library on the right side of the editor. You can search or browse through hundreds of functions available in Tableau, from simple math operations to complex date and logical functions. If you click on a function, a brief description and example syntax will appear.
At the bottom of the editor box, Tableau provides a handy status message. If your formula is syntactically correct, it will say, "The calculation is valid." If there's an error, it will try to point you to the problem.
Step 4: Click 'OK' and Find Your New Field
Once you've entered your formula and it's valid, click OK. You'll now see your new Sales Tax field in the Data pane, under the Measures section. Notice the =# sign next to it, indicating it's a numeric calculated field.
Step 5: Use Your New Field
Your new column is ready to use! You can now drag and drop the Sales Tax field onto any of the shelves - Columns, Rows, Color, Size - just like any other measure in your dataset. For example, you could drag Category to Rows and both Sales and your new Sales Tax field to the Text mark to see a table of sales tax by product category.
Common Examples of Tableau Formulas
Creating calculated fields opens up a world of possibilities. Here are a few practical examples with formulas you can adapt for your own data.
1. Combining Text Strings (Concatenation)
You have First Name and Last Name fields and want a single Full Name column.
- Field Name:
Full Name - Formula:
[First Name] + " " + [Last Name]How it works: The plus sign (+) is used to combine strings. We've added " " between the fields to insert a space between the first and last name.
2. Conditional Logic with IF Statements
You want to segment your Sales data into different sizes to quickly identify large transactions.
- Field Name:
Order Size - Formula:
IF SUM([Sales]) > 5000 THEN "Large"
ELSEIF SUM([Sales]) > 1000 THEN "Medium"
ELSE "Small"
ENDHow it works: This formula checks the sum of sales. If it's over 5000, it returns "Large." If not, it checks if it's over 1000 and returns "Medium." If neither is true, it returns "Small." The END statement is always required to close an IF block.
3. Working with Dates
You need to calculate how long it takes to ship an order after it has been placed.
- Field Name:
Days to Ship - Formula:
DATEDIFF('day', [Order Date], [Ship Date])How it works: The DATEDIFF function calculates the difference between two dates. The first argument ('day') specifies the unit of time you want the difference in. You could also use 'week', 'month', or 'year'. The next two arguments are your start and end date fields.
4. Calculating Averages or Ratios
You want to find the profit ratio for each transaction or category.
- Field Name:
Profit Ratio - Formula:
SUM([Profit]) / SUM([Sales])How it works: This is a simple aggregated calculation. It divides the sum of all profit by the sum of all sales within the context of your visualization (e.g., by category, by region, etc.). You would then want to format this field as a percentage by right-clicking it in the Data pane, going to Default Properties > Number Format... and selecting Percentage.
Managing Your New Columns
Once you've started creating columns, you'll need to know how to manage them.
- Editing a Calculated Field: If you need to make a change to a formula, simply find the field in your Data pane, right-click on it, and select Edit...
- Duplicating a Calculated Field: If you want to create a slightly different version of an existing calculation, it's often easiest to duplicate the original and modify the copy. Right-click the field and select Duplicate.
- Adding Comments: As your formulas get more complex, it's good practice to add comments to explain what you're doing. You can add a comment by starting a line with two forward slashes (
//). Tableau will ignore any text on that line when executing the formula.
Final Thoughts
Creating new columns with calculated fields is your gateway to deeper analysis in Tableau. It lets you transform raw data into the powerful, tailored dimensions and measures you need to build insightful dashboards, segment your audience, and uncover hidden trends without ever leaving the application.
We've seen how valuable creating a new view of your data is, but sometimes the friction of remembering the exact formula or logic can slow you down. It’s why we built Graphed. Instead of navigating menus and writing formulas, you can simply connect your data and ask questions like, "Show me my profit ratio for the last quarter by product category." Our AI-powered analyst handles the calculations for you, building live dashboards so you can stay focused on a conversation with your data, not the syntax.
Related Articles
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.
How to Create a Photo Album in Meta Business Suite
How to create a photo album in Meta Business Suite — step-by-step guide to organizing Facebook and Instagram photos into albums for your business page.