How to Subtract in Tableau

Cody Schneider••8 min read

Performing a simple subtraction in Tableau might sound easy, but the best method depends entirely on what you're trying to compare. You might need to find the difference between two columns, track the change between this month and last month, or compare a single store's performance to the national average. This tutorial will walk you through a few different ways to handle subtraction in Tableau, covering everything from basic calculated fields to powerful Level of Detail expressions.

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

Creating a Basic Calculated Field for Subtraction

The most straightforward way to subtract in Tableau is by creating a calculated field. This is the perfect method when you want to subtract one measure from another for each row in your dataset or subtract two aggregated measures from each other.

A common business example is calculating Cost. If your data source has columns for Sales and Profit, you can easily create a new field for Cost by subtracting Profit from Sales.

How to Create the Calculation

Creating this field is simple. Follow these steps:

  1. Navigate to the top menu and select Analysis > Create Calculated Field.
  2. A dialog box will open. Give your new field a descriptive name, like "Cost".
  3. In the formula box, type the expression. Since you are working with aggregated data (the sum of all sales and the sum of all profit), you'll want to use aggregation functions. The formula would be:
SUM([Sales]) - SUM([Profit])

Here's a breakdown of the formula:

  • SUM([Sales]): This part aggregates the total sales for the level of detail in your view (e.g., for a specific product category or region).
  • -: This is the simple subtraction operator.
  • SUM([Profit]): This aggregates the total profit for that same level of detail.

After typing the formula, Tableau will show a message below the box saying "The calculation is valid." Click OK.

You will now see your new "Cost" field in the Measures pane. You can drag and drop it into your visualization just like any other measure. For example, you could place Category on Rows and drag Sales, Profit, and your new Cost measure onto Text to see a breakdown for each category.

When to use this method: Use a simple calculated field whenever you need to find the difference between two existing measures that are at the same level of granularity in your view.

Using Table Calculations to Subtract Across Rows

Sometimes you need to subtract a value from the value in the row just above it or a few rows away. This is common when you're working with time-series data. For example, you might want to calculate the month-over-month change in revenue to see your growth trend.

This is where Tableau's table calculations come in handy. They operate on the data currently in your visualization, allowing you to perform calculations based on the position of a value in the table.

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.

Calculating Month-over-Month Change

Let's say you have a line chart showing sales over time, with the exact date on your Columns shelf and SUM(Sales) on your Rows shelf. To see the raw change from one month to the next, you need to subtract the previous month's sales from the current month's sales.

The key function here is LOOKUP(). It allows you to "look up" a value in another row.

Step-by-Step Instructions:

  1. Create a new calculated field. Let's call it "MoM Sales Change".
  2. Enter the following formula:
SUM([Sales]) - LOOKUP(SUM([Sales]), -1)

Let's break that down:

  • SUM([Sales]): This is the sales value for the current row (or data point).
  • LOOKUP(SUM([Sales]), -1): This is the magic part. The LOOKUP() function retrieves a value from a different row in the partition. The "-1" tells Tableau to look at the value from the previous row. If you wanted to compare in the other direction, you could use a positive integer.

Handling the First Data Point (Nulls)

You'll notice that the very first data point in your calculation (the first month) is blank. This is because there is no previous month (-1) to subtract from. This often results in a "null" value, which can sometimes break calculations or just look messy.

To fix this, you can wrap the calculation in the ZN() function, which stands for "Zero Nulls". It converts any null values to 0.

Your modified formula would be:

ZN(SUM([Sales])) - ZN(LOOKUP(SUM([Sales]), -1))

This version ensures your calculation always returns a number, which can be much neater for downstream analysis or dashboards.

Configuring "Compute Using"

After adding a table calculation, you need to tell Tableau how to apply it. Right-click your table calculation pill in the view and select "Compute Using". You'll see options like "Table (across)" or "Table (down)." For a time-series chart, selecting "Table (across)" is typically correct, as it computes the difference from left to right along your date axis.

When to use this method: Use table calculations when you want to calculate differences based on position, like comparing a value to the previous, next, first, or last row.

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

Comparing to a Fixed Value with LOD Expressions

What if you want to subtract a value that isn't dependent on the other fields in your visualization? Let’s say you want to compare each state's sales against the average for their whole region, no matter how you filter the data later.

For this kind of subtraction, a simple aggregated calculation or a table calculation won't work correctly. You need to use a Level of Detail (LOD) expression. LOD expressions allow you to compute values at a specific level of granularity, independent of your visualization's dimensions.

Example: Comparing State Sales to Regional Average

Imagine your view shows a table with Region, State, and SUM(Sales). You want to add a fourth column: how far above or below the regional average is each state's sales total?

First, you need to calculate the average sales for each region. To do this, we'll use a FIXED LOD expression.

1. Create the Regional Average LOD

Create a calculated field named "Regional Average Sales" with the following formula:

{FIXED [Region] : AVG([Sales])}

This formula tells Tableau: "For each unique Region, calculate the average of sales and 'fix' it." This means that every single row of data that belongs to the "East" region will now have the same "Regional Average Sales" value attached to it, regardless of the state or any other dimension.

2. Create the Subtraction Calculation

Now, create a second calculated field. Let's name it "Sales vs Regional Avg".

The formula is a simple subtraction, but it combines a regular aggregation with our new LOD calculation:

SUM([Sales]) - MIN([Regional Average Sales])

Why MIN()? Or why ATTR() or AVG()? Since the LOD expression returns the same value for every row within a region, you have to aggregate it in your final view. Using MIN(), MAX(), AVG(), or ATTR() will all return the same correct value because you are aggregating identical numbers. We use one of these to satisfy Tableau's requirement that all fields in a calculation are either aggregated or not aggregated.

When you drag this new field into your table, you will see a value representing how much higher or lower that state's sales are compared to the average for its region.

When to use this method: Use LOD expressions when you need to subtract a value calculated at a different, often broader, level of detail than what's currently shown in your visualization.

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.

Subtracting Dates with DATEDIFF

Another very frequent use case for subtraction in Tableau is finding the difference between two dates. For this, Tableau has a specific function: DATEDIFF().

The DATEDIFF function calculates the time duration between a start date and an end date. You can specify the unit of time you want back - be it days, weeks, months, or years.

Calculating Shipping Time

Suppose you have data with an Order Date and a Ship Date, and you want to know how many days it took to ship each order.

How to Create the Calculation

  1. Create a new calculated field called "Days to Ship".
  2. Use the DATEDIFF function in the formula box:
DATEDIFF('day', [Order Date], [Ship Date])

The syntax is straightforward:

  • 'day': This is the date part. You can also use 'week', 'month', 'quarter', 'year', etc. It must be in single quotes and lowercase.
  • [Order Date]: This is the start date field.
  • [Ship Date]: This is the end date field.

The result of this calculation will be an integer representing the number of days between the two dates for each order. You can use this new measure to find average shipping times, spot outliers, and more.

When to use this method: Always use DATEDIFF when you need to find the interval between two date fields in your data.

Final Thoughts

While the concept is simple, subtraction in Tableau is powerful because of the different contexts in which it can be applied. You can use basic calculated fields for direct measure comparisons, table calculations for positional analysis like month-over-month trends, LOD expressions for comparing against a fixed benchmark, and DATEDIFF for duration calculations. Choosing the right method will help you turn your raw data into meaningful insights.

Mastering these functions in a tool like Tableau takes time and can feel like a steep learning curve. We built Graphed because we believe getting answers from your data shouldn't require you to become an expert in formula syntax first. Instead of trying to remember the difference between LOOKUP() and a FIXED LOD, you can just ask a question in plain English, like "Show me month over month revenue change," and get a live, interactive dashboard built for you automatically. It connects directly to your data sources and automates the reporting work, so you can spend less time writing functions and more time acting on your insights.

Related Articles