How to Divide Two Columns in Tableau

Cody Schneider••8 min read

Dividing one column by another in Tableau is one of the first things you’ll need to do when analyzing performance. Whether you're calculating a cost per acquisition, a profit ratio, or an average price per unit, division is the key. This article covers the most common and effective method for dividing columns - calculated fields - and also shows you how to handle common errors like division by zero.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

The Best Method: Creating a Calculated Field

The most flexible and powerful way to divide columns in Tableau is by using a calculated field. A calculated field is a new field (or column) that you create in your data source by using a formula. This formula can reference other fields, perform math, manipulate text, or apply logical conditions. The new field you create can then be used in any visualization, just like your original data.

Let's walk through a common marketing scenario. Imagine you have data from your ad campaigns with two columns: [Spend] and [Conversions]. To understand campaign efficiency, you need to calculate the Cost Per Acquisition, or CPA. The formula is simple: Spend ÷ Conversions.

Here’s how to build that in Tableau.

Step-by-Step Guide to Division with a Calculated Field

For this example, we’ll assume you have a data source connected to Tableau that contains your campaign data.

1. Create a New Calculated Field

In the Data pane on the left side of your screen, find the data source you're working with. You can either right-click on an empty space of the pane or click the small dropdown arrow to the right of the Data pane title. From the menu, select Create Calculated Field…

2. Name Your New Field

A dialog box will appear. The first thing you should do is give your new field a descriptive name. This name will appear in your Data pane just like any other field. Let's call this one "CPA (Cost Per Acquisition)". A good name makes your analysis easier to understand later.

3. Write the Division Formula

Now for the formula itself. In the large text area of the dialog box, you'll write the expression to divide your columns. You might be tempted to just write [Spend] / [Conversions], but it's better to use aggregations.

Type the following formula:

SUM([Spend]) / SUM([Conversions])

When you have a valid formula, Tableau will show a message at the bottom of the dialog that says, "The calculation is valid." Click OK to create the field.

That's it! You've successfully created a new measure called "CPA (Cost Per Acquisition)". You'll find it in your Data pane under the "Measures" section. Now you can drag it into your rows or columns shelf to visualize your campaign efficiency.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Why Is Using SUM() So Important? The Role of Aggregation

One of the most important concepts to grasp in Tableau is aggregation. When you drag a number field (a "measure") onto a visualization, Tableau automatically aggregates it. Most of the time, this aggregation is SUM(). For example, if you drag [Spend] to the Rows shelf, you will see a green pill that says SUM(Spend), not just [Spend].

This means Tableau is summing up all the Spend values for the level of detail in your view. If you have "Campaign Name" defining your rows, it will sum up all the Spend for each campaign.

Your calculated fields should almost always use the same aggregations. Here's why:

  • Aggregate Calculation (Correct):
  • Row-Level Calculation (Often Incorrect for Ratios):

Rule of thumb: When dividing two measures to create a performance ratio (like cost per click, conversion rate, or average order value), always wrap both measures in an aggregation like SUM(), AVG(), or COUNTD().

Handling an Extremely Common Problem: Division by Zero

What happens if a campaign received zero conversions? Your SUM([Conversions]) would be zero, and you can't divide by zero. Computers don't like it, and Tableau is no exception.

When Tableau encounters a division-by-zero scenario, it typically returns a Null value. This means that part of your chart will be blank, which might be confusing for your audience. For example, a campaign with high spend but zero conversions would just disappear from your CPA chart.

A better approach is to explicitly tell Tableau what to do in these situations. You can replace the Null value with a 0 or some other indicator.

Here are two functions to fix this.

Solution 1: The IF Statement

You can use a simple IF/THEN/ELSE statement to check if the denominator is zero. If it is, you can tell Tableau to return 0 instead of trying to perform the impossible division.

Edit your calculated field to look like this:

IF SUM([Conversions]) = 0 THEN
    0
ELSE
    SUM([Spend]) / SUM([Conversions])
END

This logic reads just like plain English: "If the sum of conversions is zero, then return 0. Otherwise (else), calculate the CPA as usual." This makes your chart cleaner and your analysis more robust.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Solution 2: The ZN() Function

The ZN() function is a neat shortcut in Tableau that stands for "Zero Null". Its job is to take a null value and change it into a zero. To prevent unexpected behaviors in your denominator, the most solid approach is still the IF statement. But there’s another popular option: using a formulaic workaround that blends division and ZN():

ZN(SUM([Spend])) / ZN(IIF(SUM([Conversions]) = 0, NULL, SUM([Conversions])))

This might appear complicated at first, so let’s see a step-by-step breakdown:

  • The code checks if SUM([Conversions]) is 0, if so, it replaces it with Null.
  • To avoid errors, you wrap the denominator with the ZN() function.
  • In summary, IIF can address the divide-by-zero problem when used in combination with ZN(), but ZN() alone can't.

Advanced Tip: What About Different Data Types?

Occasionally, you might find that you can't divide two columns because they have different data types. Tableau is usually smart about this, but sometimes you may have a number stored as a string (text), marked with "Abc" in the Data pane. You can't perform math on a string.

In this case, you need to convert the string to a number within your calculated field. You can use functions like:

  • FLOAT(): Converts a string to a decimal number. Example: FLOAT([Spend as String])
  • INT(): Converts a string to a whole number. Example: INT([Conversions as String])

Your finished formula, now including data type conversion and the zero-division fix, might look like this:

IF SUM(INT([Conversions as String])) = 0 THEN
    0
ELSE
    SUM(FLOAT([Spend as String])) / SUM(INT([Conversions as String]))                   
END

Mastering this simple syntax will significantly reduce friction while formatting your dataset.

Alternative Approach: Quick Table Calculations

Another powerful yet different concept in Tableau is table calculations. While calculated fields create a new, reusable field in your data source, table calculations perform computations on the values currently in your view. They are quick, but context-dependent.

One common use is calculating totals. Imagine a table of "Conversions Rate by Ad Campaign in % by region". To obtain that “conversion in % part” instead of needing to define a new calculated field, all you would need to do is:

1. Right-clicking a Measure

Right-click the measure you wish to analyze and from the dropdown menu, select Add Table Calculation.

2. Customize your Calculation

This new function lets you perform diverse operations in this new field such as seeing: difference, % differences, percentiles, ranking, moving average, among other advanced mathematical relationships with this data point you wish to study.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Which One to Use? A Simple Guide

Calculated Fields:

Use them if you're not planning to alter or reorganize these results. You’ll just add a "permanent" column. The field will remain in the side toolbar, under ‘Custom Columns’ in your Dataset panel to the left.

Table Calculations:

Use when you only need the result view ‘in context’ for further analysis on the same Worksheet, to be discarded later. They're not meant to create a permanent column. You can obtain a result to be put aside and then remove it as it could over-complicate your view. It won't be saved unless you specifically save it into a new worksheet. In most cases where you see this technique being applied, this temporary view of a table isn’t saved as it’s made purely for contextual decisions over which other actions derive.

The golden rule? If you want to analyze or filter any newly calculated data to use across different views, then choose calculated fields from the start. If what you’re trying to build is an advanced calculation using other external functions like forecasting trend lines or running totals across custom dates, then using table calculations can be more handy to try and experiment as much as you need within minutes.

Final Thoughts

Dividing columns is a fundamental task in Tableau, and using a calculated field is the most reliable way to do it. By always using aggregations like SUM() and proactively handling division-by-zero errors with an IF statement, you can build clean, accurate analyses that effectively communicate your business performance.

As robust as tools like Tableau are, mastering aggregations, learning special functions, and handling data type errors still presents a learning curve. That’s why we built Graphed . We wanted to make performance analysis instant for everyone on the team. Instead of writing formulas to calculate your CPA, you just ask a question like, "Show me cost per acquisition by campaign as a bar chart," and Graphed generates the dashboard for you in real time.

Related Articles