How Do You Filter by Formula in Tableau?

Cody Schneider8 min read

Dragging dimensions or measures to the Filters shelf is one of the first things you learn in Tableau, but what happens when a simple drag-and-drop isn't enough? You can get a lot more power and precision by filtering your view using a custom formula. This article will show you exactly how to create and apply calculated field filters for more dynamic and insightful dashboards.

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

What Does It Mean to Filter by a Formula?

Filtering by a formula means you’re not just filtering on the raw values in your data (like "Region" or "Sales"). Instead, you create a new field - a Calculated Field - that contains specific logical conditions. You then use this calculated field as your filter.

The core concept usually revolves around a formula that returns a boolean value: either True or False. When you drag this calculated field to the Filters shelf, Tableau will ask you if you want to include the "True" values or the "False" values. By keeping only the "True" values, you effectively apply your custom logic to the entire visualization.

Why Would You Use a Formula to Filter?

This approach unlocks a level of flexibility that standard filters can't match. Here are a few common scenarios where a formula filter is the best solution:

  • Multi-Condition Filtering: You need to filter based on multiple criteria from different fields. For example, showing only products where Sales > $10,000 and Profit Margin > 15%.
  • Dynamic Date Ranges: You want a report that always shows data for the "last 30 days" or "this quarter to date" without needing manual updates.
  • Advanced String Matching: You need to find values that meet specific text patterns, like identifying all customer support tickets that mention the words "refund" or "defective."
  • Comparing Against Aggregates: You want to see which sales reps are performing above the average sales for their region.
  • User-Driven Filters with Parameters: You want to build an interactive dashboard where users can input a value (like "Show me my Top 10 products") and the view filters accordingly.

Step-by-Step Guide: Your First Formula Filter

Let's walk through a common business scenario. Imagine you're an e-commerce manager analyzing product data. You want to isolate your "star performers" - products that not only sell well but are also highly profitable. A simple filter on sales isn't enough, nor is one on profit alone. You need both.

Our Goal: To create a view that only shows product sub-categories with more than $80,000 in total sales and a profit of more than $15,000.

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.

Step 1: Create a New Calculated Field

First, we need to create the calculated field that will hold our logic. In Tableau, find the Data pane on the left side of your screen. Click the small drop-down arrow at the top of the pane and select "Create Calculated Field..."

Alternatively, you can right-click anywhere within the Data pane and choose the same option.

Step 2: Write the Formula

A dialog box will pop up. This is the calculated field editor. Your first step should always be to give your calculation a descriptive name. Let’s call it "Profitable High-Sellers Filter".

In the main window of the editor, type the following formula. This formula checks for our two conditions:

SUM([Sales]) > 80000 AND SUM([Profit]) > 15000

Let's break down this formula:

  • SUM([Sales]) > 80000: This part checks if the total sales for a given mark on your visual (in our case, a product sub-category) are greater than $80,000. It returns True if they are, False if not.
  • AND: This is a logical operator. It tells Tableau that both the condition on the left and the condition on the right must be true for the final output to be true.
  • SUM([Profit]) > 15000: This checks if the total profit for that same mark is greater than $15,000.

Essentially, for each sub-category in our view, this calculation will ask, "Are sales over $80k AND is profit over $15k?" If the answer is yes, it returns True. If not, it returns False.

Click "OK" to save your calculated field. You’ll now see "Profitable High-Sellers Filter" in your Data pane, usually under the Measures section with a T|F icon indicating it’s a boolean field.

Step 3: Apply the Calculated Field as a Filter

Now for the easy part. Build a simple view, for instance, a horizontal bar chart showing Sales by Sub-Category.

Next, find your new "Profitable High-Sellers Filter" calculated field in the Data pane. Click and drag it directly onto the Filters shelf.

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

Step 4: Select "True"

As soon as you drop the field on the Filters shelf, a new dialog box will appear. Because our calculation produces a boolean output, Tableau asks which values you want to include. Check the box next to "True" and click "OK."

Instantly, your bar chart will update. The only sub-categories remaining will be the ones that meet both of our conditions. You've successfully filtered your data using a custom formula!

More Practical Examples of Formula Filters

An AND condition is just the beginning. Let’s explore a few more examples to see how versatile this technique can be for common business questions.

Example 1: Dynamic Date Range Filter

Manually updating date filters is tedious. A dynamic filter keeps your dashboard current automatically.

Goal: Create a filter to show sales from only the last 30 days, which updates automatically every day.

Calculated Field Name: Last 30 Days Filter

Formula: DATEDIFF('day', [Order Date], TODAY()) <= 30

What this formula does:

  • TODAY(): This function returns the current date.
  • DATEDIFF('day', [Order Date], TODAY()): This calculates the difference in the number of days between the Order Date of each record and today's date.
  • <= 30: The formula returns True for any row where the difference is 30 days or less.

Drag this field to Filters, select "True," and your view will now always show a rolling 30-day window.

Example 2: Filtering with String Functions

Sometimes you need to find records based on text values that aren't exact matches.

Goal: Analyze product revenue but exclude all internal test products, which are always named with a "TEST-" prefix.

Calculated Field Name: Is Not Test Product

Formula: NOT STARTSWITH([Product Name], "TEST-")

What this formula does:

  • STARTSWITH([Product Name], "TEST-"): Checks if the Product Name string begins with "TEST-". Returns True if it does.
  • NOT: Reverses the boolean output, so if STARTSWITH is True, the NOT makes it False.

Drag this calculation to the Filters shelf and set it to "True" to filter out all your test products.

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.

Example 3: Interactive Top N Filter with a Parameter

This is a more advanced technique that makes your dashboards highly interactive for your audience.

Goal: Let users choose whether they want to see the Top 5, 10, or 20 customers by sales from a dropdown menu.

Part A: Create the Parameter

  1. In the Data pane, click the drop-down arrow and choose "Create Parameter...".
  2. Name it Select Top N.
  3. Set Data type to Integer.
  4. Under "Allowable values," select List.
  5. In the "List of values" section, add the values 5, 10, and 20.
  6. Click "OK." Then right-click the parameter in the Data pane and select "Show Parameter." It will now appear on your worksheet as a control.

Part B: Create the Calculated Filter Our filter needs to rank customers by sales and compare that rank to the number the user selected in the parameter.

Calculated Field Name: Top N Filter

Formula: RANK(SUM([Sales])) <= [Select Top N]

This formula compares the rank of each customer (based on the sum of sales) to the value selected in our parameter. Apply this to the filters shelf, select True, and ensure the table calculation is computed by Customer Name.

Tips for Success

  • Use Descriptive Names: "Calculation 1" won’t help you six months from now. Name your calculations logically, like "YoY Growth Filter" or "In-Stock Products."
  • Understand Aggregations: Pay close attention to when you should and shouldn’t use aggregations like SUM(), AVG(), or MAX(). A formula like [Sales] > 1000 checks every single row of your data, while SUM([Sales]) > 1000 checks the aggregated value for the dimensions in your view. They answer very different questions.
  • Add Comments: For complex logic, you can add comments to your formula to explain what it does. Simply start a line with two slashes //. For example: // This filter finds profitable orders over $500.

Final Thoughts

Learning to filter by formula is a huge step toward mastering Tableau. It bridges the gap between basic drag-and-drop operations and building truly dynamic, tailored reports that answer complex business questions. You can now combine multiple conditions, create dynamic date ranges, and make your dashboards interactive for your team.

While mastering formulas in Tableau is a powerful skill, sometimes you just need a direct answer without writing calculations. At Graphed, we specialize in getting you those answers instantly. Instead of building multi-step filters or complex parameters, you can simply ask in plain language, "Show me a dashboard of my top 10 most profitable products from the last 90 days." Our platform connects to your tools (like Google Analytics, Shopify, and Salesforce) and builds the live dashboard for you in seconds, saving you from the busywork of data wrangling.

Related Articles