How to Create a New Variable in Tableau
Creating custom variables in Tableau is your secret weapon for unlocking deeper insights from your raw data. Instead of being limited to the fields in your dataset, you can build new dimensions and measures to analyze performance in a way that truly matters to your business. This article will walk you through how to create and use new variables in Tableau, focusing on the powerful Calculated Fields feature.
Why Create a New Variable in Tableau?
Your raw data is a great starting point, but it rarely tells the whole story. You need to manipulate, segment, and combine fields to answer specific business questions. Creating a new variable - which in Tableau is most often called a Calculated Field - allows you to:
- Calculate Custom Metrics: Your data source might have "Sales" and "Profit," but not "Profit Margin." You can create a variable to calculate this instantly.
- Segment Your Data: You might want to group customers into categories like "High Value," "Medium Value," and "Low Value" based on their total spending. A calculated field makes this easy.
- Flag Key Information: Create a true/false flag to identify orders that were discounted, customers who purchased more than once, or sales that exceeded a certain target.
- Clean and Transform Data: You can create new variables to correct inconsistencies, extract pieces of text (like a first name from a full name), or create custom date groupings (like fiscal quarters).
Moving beyond the default fields is where real analysis begins. It's how you tailor your dashboard to your specific goals and uncover trends you would have otherwise missed.
The Heart of Tableau Variables: Calculated Fields
The most common and powerful way to create a new variable in Tableau is by using a calculated field. Think of a calculated field as an empty column in a spreadsheet that you fill with the results of a formula. That formula can reference other fields in your data, perform calculations, implement conditional logic, and more.
Once created, your new calculated field appears in the Data pane just like any other field, ready to be dragged and dropped into your visualizations.
Step-by-Step: How to Create a Basic Calculated Field
Let's walk through the process of creating a new variable. It's surprisingly straightforward.
- Navigate to the Data pane on the left side of your Tableau worksheet.
- Right-click anywhere in the empty space of the pane (or on the field you plan to use in your calculation).
- Select Create Calculated Field from the context menu.
This opens the calculation editor, which has a few key parts:
- Field Name: At the top, you’ll name your new variable. Give it a clear, descriptive name (e.g., "Profit Ratio" instead of "Calc1").
- Formula Area: This large white space is where you will write your formula. You can either type field names directly (Tableau will autocomplete them) or drag them from the Data pane.
- Function List: To the right, you can browse all available Tableau functions, categorized by type (Number, String, Date, etc.). Clicking a function provides a helpful description and an example of its syntax.
- Validation Status: At the bottom, a message will tell you if your formula is valid ("The calculation is valid") or if there's an error.
Once you've written your formula and given it a name, simply click "OK," and your new variable will appear in the Data pane, ready for use.
Practical Examples: Custom Variables in Action
Theory is great, but let's build a few common and incredibly useful variables using calculated fields. We'll use the sample "Superstore" dataset that comes with Tableau for these examples.
Example 1: Basic Math – Calculating Profit Ratio
Your data has Sales and Profit, but the key metric you want to track is the profit ratio - what percentage of sales is ending up as profit? This requires a new variable.
Goal: Create a "Profit Ratio" measure.
- Create a new calculated field and name it "Profit Ratio."
- In the formula box, type:
SUM([Profit]) / SUM([Sales])
What's happening here? We are telling Tableau to aggregate the profit for whatever slice of data is being shown (e.g., a specific product category or region) and then divide it by the aggregated sales for that same slice. Using aggregations like SUM(), AVG(), or MIN() is critical in Tableau calculations.
After clicking "OK," you'll see "Profit Ratio" in the Data pane. Right-click it, go to Default Properties → Number Format → Percentage to ensure it always displays correctly.
Example 2: Conditional Logic with IF/THEN – Customer Segmentation
Conditional logic is where you can start adding real business intelligence. Let's create a variable to segment sales orders into "Small," "Medium," and "Large" sizes.
Goal: Create a new dimension called "Order Size."
- Create a new calculated field named "Order Size."
- Use an IF statement to define the logic:
IF SUM([Sales]) > 1000 THEN 'Large Order' ELSEIF SUM([Sales]) > 200 THEN 'Medium Order' ELSE 'Small Order' END
What's happening here? Tableau evaluates each row or mark against this logic. If the sum of sales is greater than 1000, it assigns the string "Large Order." If not, it checks the next condition (is it greater than 200?), and so on. The END statement is required to close the IF block. You can now use this new "Order Size" dimension to color a bar chart or see what percentage of your profit comes from each size.
Example 3: Working with Dates – Is a Sale a Weekend Sale?
Your Order Date field tells you the exact date of a transaction. But what if you want to analyze performance on weekdays versus weekends?
Goal: Create a "Weekday/Weekend" dimension.
- Create a new calculated field called "Order Day Type."
- Use a date function and an
IIFstatement - a more compact version ofIF/THEN.
IIF(DATEPART('weekday', [Order Date]) = 1 OR DATEPART('weekday', [Order Date]) = 7, 'Weekend', 'Weekday')
What's happening here? The DATEPART('weekday', [Order Date]) function returns a number for the day of the week (where 1 is Sunday and 7 is Saturday in Tableau's default settings). The IIF statement checks if that number is a 1 OR a 7. If it is, it returns "Weekend", otherwise, it returns "Weekday." Now you have a simple variable to compare performance across these two crucial categories.
For the More Advanced: Level of Detail (LOD) Expressions
As you get more comfortable, you'll encounter situations where a standard aggregation doesn't work. For example, what if you want to calculate the average sales per customer and then average that value across different regions?
This is where Level of Detail (LOD) expressions come in. They let you create variables by calculating aggregates at a level of granularity independent of what's in your view.
Example: Flagging a Customer's First Purchase
Let's say you want to compare customer behavior on their first purchase versus all subsequent purchases. You need a variable that returns the date of their very first purchase, no matter what other dimensions are in your viz.
Goal: Create a "First Purchase Date" field for each customer.
- Create a new calculated field called "First Purchase Date."
- Use a FIXED LOD expression:
{FIXED [Customer Name] : MIN([Order Date])}
What's happening here? This formula tells Tableau: "For each unique Customer Name, find the minimum Order Date and return that date." This value is now attached to every one of that customer's records, allowing you to create another calculation like:
IIF([Order Date] = [First Purchase Date], 'First Purchase', 'Repeat Purchase').
Final Thoughts
Creating new variables through calculated fields is arguably the most important skill to master in Tableau. It elevates your analysis from simply reporting raw data to building custom, meaningful insights that answer critical business questions. By learning to combine fields with math, logic, and date functions, you can transform any dataset into a powerful analytical tool.
Of course, mastering all the different functions and formulas in a tool like Tableau takes time and can feel intimidating, especially when you just need a quick answer. At my company, we've focused on simplifying this process. With Graphed , you don't need to write formulas at all. You can just ask in plain English, "Show me my profit ratio by product category" or "Group my customers into high, medium, and low value segments," and it builds the visualization for you instantly. By connecting all your data sources, we let you ask questions and get answers in seconds, turning hours of data wrangling into a simple conversation.
Related Articles
How to Connect Facebook to Google Data Studio: The Complete Guide for 2026
Connecting Facebook Ads to Google Data Studio (now called Looker Studio) has become essential for digital marketers who want to create comprehensive, visually appealing reports that go beyond the basic analytics provided by Facebook's native Ads Manager. If you're struggling with fragmented reporting across multiple platforms or spending too much time manually exporting data, this guide will show you exactly how to streamline your Facebook advertising analytics.
Appsflyer vs Mixpanel: Complete 2026 Comparison Guide
The difference between AppsFlyer and Mixpanel isn't just about features—it's about understanding two fundamentally different approaches to data that can make or break your growth strategy. One tracks how users find you, the other reveals what they do once they arrive. Most companies need insights from both worlds, but knowing where to start can save you months of implementation headaches and thousands in wasted budget.
DashThis vs AgencyAnalytics: The Ultimate Comparison Guide for Marketing Agencies
When it comes to choosing the right marketing reporting platform, agencies often find themselves torn between two industry leaders: DashThis and AgencyAnalytics. Both platforms promise to streamline reporting, save time, and impress clients with stunning visualizations. But which one truly delivers on these promises?