How to Divide Two Measures in Tableau
Dividing two numbers is simple math, but in Tableau, it's the key to unlocking fundamental business metrics like conversion rates, average order value, and cost per acquisition. While the basic operation is straightforward, understanding how to do it correctly - especially when dealing with aggregations and potential errors - is what separates a confusing chart from a powerful insight. This tutorial will walk you through creating division calculations in Tableau, handling common pitfalls, and formatting your results for a clean, professional dashboard.
Why Divide Measures in Tableau?
Before jumping into the “how,” let’s quickly cover the “why.” Division is one of the most common operations in data analysis because it turns raw numbers into meaningful ratios and rates. It helps you establish relationships and benchmarks by putting your data into context.
Here are a few popular examples:
- Conversion Rate: Calculating the percentage of users who take a desired action. Example:
Total Orders / Total Website Sessions. - Average Order Value (AOV): Finding the average revenue generated per order. Example:
Total Sales / Number of Orders. - Cost Per Acquisition (CPA): Determining how much you spend to acquire one customer. Example:
Total Ad Spend / Number of New Customers. - Profit Margin: Measuring the profitability of a product or service. Example:
(Sales - Cost) / Sales. - Percentage of Total: Showing how a segment contributes to the whole. Example:
Sales from a Specific Category / Total Sales.
Each of these metrics relies on a simple division calculation that you can create directly within Tableau.
The Standard Method: Creating a Calculated Field
The most robust and reusable way to divide measures is by creating a calculated field. This saves your formula as a new measure in your data pane, allowing you to use it across multiple worksheets just like any other field.
Step 1: Open the Calculated Field Editor
First, you need to open the editor where you'll write your calculation. You can do this in a couple of ways:
- In the Data pane (the sidebar on the left), right-click on any empty space and select Create Calculated Field.
- Alternatively, navigate to the top menu and click Analysis > Create Calculated Field....
Either option will open a new window for your formula.
Step 2: Name Your Calculation
At the top of the window, you'll see a text box ready for your field name. It's a best practice to give your calculation a clear, descriptive name. Instead of "Calculation1," use something like "Conversion Rate" or "Average Order Value." This makes your work understandable for both you and anyone else who might use your dashboard.
Free PDF Guide
AI for Data Analysis Crash Course
Learn how to get AI to do data analysis for you — the best tools, prompts, and workflows to go from raw data to insights without writing a single line of code.
Step 3: Write the Division Formula
Now for the main event. The basic syntax for division is exactly as you'd expect: one measure divided by another, using the slash (/) symbol. To use a measure from your data source, you enclose its name in square brackets [].
For example, if you wanted to find the ratio of profit to sales, you might initially think to write:
[Profit] / [Sales]While this is syntactically correct, it leads to a critical concept in Tableau: aggregations.
Step 4: A Crucial Detail - Using Aggregations
When you place measures on a Tableau viz, Tableau automatically aggregates them—usually by summing (SUM) them up. If you write a calculation without an aggregation like [Profit] / [Sales], Tableau performs the division for every single row of your data first, then aggregates the results (e.g., sums up all the individual row-level profit ratios). This is rarely what you want.
Most of the time, you want to divide the total of one measure by the total of another. To do this, you must include the aggregation functions directly in your calculation formula.
The correct formula for calculating the overall profit ratio would be:
SUM([Profit]) / SUM([Sales])This tells Tableau to first calculate the sum of all profit values, then calculate the sum of all sales values, and only then divide the two totals. This ensures your calculation is accurate at whatever level of detail your visualization is set to (e.g., by month, by region, or for the entire dataset).
Always ask yourself: "Am I trying to calculate this rate for each individual row, or for a total group?" Nine times out of ten, you'll be working with totals, so remember to use SUM(), AVG(), COUNT(), or another aggregation function.
Step 5: Save and Use Your New Measure
Once you've entered your formula, look for a message at the bottom of the editor that says "The calculation is valid." If there's an error, Tableau will provide a hint about what's wrong.
Click OK to save the calculated field. Your new measure will now appear in the Data pane, usually under the "Measures" section, accompanied by an equals sign (=) next to its icon to indicate it's a calculated field. Now you can drag and drop it onto your shelves just like any other measure!
Handling a Common Problem: Division by Zero
What happens if your denominator is zero? In mathematics, division by zero is undefined. In Tableau, it results in a Null value, which often shows up as a blank space in your chart or table. This can be confusing and lead to incomplete-looking dashboards.
It's always better to handle this scenario intentionally. Here are two ways to do it.
Method 1: Using the ZN() Function
The ZN() function stands for "Zero Null." It takes a field as input and returns the field's value if it is not null, or 0 if it is null.
You can wrap your denominator with ZN() to handle cases where the field might be entirely null.
SUM([Sales]) / ZN(SUM([Orders]))Note: ZN() is useful for converting nulls to zero, but if SUM([Orders]) is already zero, this won't prevent division-by-zero issues. That's where the next method comes in.
Method 2: The Best Practice - Using an IF Statement
The most reliable way to prevent division-by-zero errors is to check the denominator's value before you perform the division. You can do this with a simple IF statement.
IF SUM([Orders]) > 0 THEN SUM([Sales]) / SUM([Orders]) ELSE 0 ENDLet's break down what this formula does:
IF SUM([Orders]) > 0: Checks if the total number of orders is greater than zero.THEN SUM([Sales]) / SUM([Orders]): If true, perform the division.ELSE 0: If false (orders are zero or less), return 0.END: Closes theIFstatement.
This approach gives you complete control over the outcome and makes your visualizations more polished and easier to understand.
Free PDF Guide
AI for Data Analysis Crash Course
Learn how to get AI to do data analysis for you — the best tools, prompts, and workflows to go from raw data to insights without writing a single line of code.
Formatting Your New Measure
After creating your calculated field, you might notice the numbers aren't formatted correctly. A conversion rate might appear as "0.0543" when you really want to see "5.43%", or an AOV might show too many decimal places.
You can easily set the default number format for your new measure.
- Find your calculated field in the Data pane.
- Right-click on it and go to Default Properties > Number Format...
- A dialog box will open with a list of formats.
- Choose the appropriate format:
- Click OK.
By setting the default format, Tableau will apply this styling every time you drag the field into a new view, saving you time and ensuring consistency.
Putting It All Together: A Practical Example
Let’s calculate an e-commerce Cost Per Order (CPO) and visualize it by advertising campaign.
Imagine your data source contains the fields Ad Spend and Orders faceted by an Ad Campaign dimension.
- Create the Calculated Field: Right-click in the Data pane, select Create Calculated Field, and name it "Cost Per Order".
- Write the Formula (with error handling):
IF SUM([Orders]) > 0 THEN SUM([Ad Spend]) / SUM([Orders]) ELSE 0 END- Set the Default Formatting: Right-click "Cost Per Order," go to Default Properties > Number Format, and choose Currency (Standard) with 2 decimal places. Click OK.
- Build the Visualization:
Just like that, you have a bar chart showing the CPO for each campaign. Because you used an IF statement, any campaign with zero orders will show a CPO of $0.00 instead of a blank space, making for a much cleaner visualization.
Final Thoughts
Mastering division in Tableau is all about creating aggregated calculations using calculated fields. When you build these formulas, always remember to check for potential division-by-zero errors and use an IF statement to handle them proactively. Taking a few moments to set the default number formatting will then add the final professional touch to your dashboard.
Connecting data and calculating performance metrics across different tools is often the biggest reporting challenge. Marketers frequently need to divide a metric from one platform (like Shopify revenue) by a metric from another (like Facebook Ad Spend) to see what's actually working. Instead of exporting CSVs and wrestling with formulas manually, we built Graphed to do the heavy lifting for you. You can connect your data sources in a few clicks and simply ask questions like, "Show me a chart of my Shopify sales divided by my Facebook Ads spend" and get an answer instantly, creating a real-time dashboard that keeps itself up to date.
Related Articles
Facebook Ads for Hair Salons: The Complete 2026 Strategy Guide
Learn how to run profitable Facebook ads for hair salons in 2026. This guide covers audience targeting, ad creatives, retargeting strategies, and budget optimization to get more bookings.
Facebook Ads For Yoga Studios: The Complete 2026 Strategy Guide
Learn how to use Facebook ads for yoga studios to drive trial memberships and grow your practice in 2026. Complete setup guide, expert tips, and retargeting strategies.
Facebook Ads for Plumbers: The Complete 2026 Strategy Guide
Learn how to run profitable Facebook ads for plumbers in 2026. This comprehensive guide covers high-converting offers, targeting strategies, and proven tactics to grow your plumbing business.