Can Sets Be Used in Calculations in Tableau?

Cody Schneider••7 min read

Yes, you absolutely can use sets in calculations in Tableau, and it's one of the most powerful and flexible ways to perform sophisticated data segmentation. This functionality lets you group members of a dimension based on specific conditions and then reference that group directly within your calculated fields. In this guide, we'll walk through how sets work, how to use them in calculations step-by-step, and explore some practical examples to get you started.

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 Are Tableau Sets?

Think of a Tableau set as a custom field that creates a binary grouping of your data. Based on conditions you define, any member of a dimension is either "IN" the set or "OUT" of the set. This simple IN/OUT logic is the foundation that makes sets so useful in calculations.

There are two main types of sets you can create:

  • Constant Sets (Static): These are manually created by selecting specific members from a list. The members of a constant set don't change unless you manually edit the set. For example, you could create a set containing your top three performing regions from last year.
  • Dynamic Sets: These are the real heavy-hitters. Dynamic sets automatically update as the underlying data changes, based on a rule or condition you've set up. You could create a dynamic set for "Customers with Sales over $10,000" or "Products in the Top 10% by Profit." As your sales data updates, the members of this set will change automatically.

The Foundation: Using the IN/OUT Logic in a Calculation

When you drag a set into the view or reference it in a calculated field, Tableau doesn't return the names of the members. Instead, it returns a simple "IN" for members that meet the set's criteria and "OUT" for those that don't.

This simple true/false state is perfect for using in IF/THEN statements, which are the building blocks of creating calculations with sets. You can essentially tell Tableau, "IF a member is IN this set, then do this calculation, otherwise, do something else."

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.

How to Use a Set in a Calculated Field: A Step-by-Step Example

Let's walk through a common business scenario: segmenting your top customers from the rest of the customer base to analyze their specific contribution to sales. We'll use the Sample - Superstore dataset included with Tableau for this example.

Our goal is to create a bar chart that shows total sales for "Top 10 Customers" versus "All Other Customers."

Step 1: Create a Dynamic Set of Top Customers

First, we need to define which customers belong in our "Top 10" group.

  1. In the Data pane on the left, find the Customer Name dimension.
  2. Right-click on Customer Name and select Create > Set.
  3. In the Create Set dialog box, give the set a descriptive name, like Top 10 Customers by Sales.
  4. Go to the Top tab.
  5. Select By field. Configure it to read: Top 10 by Sum of Sales.
  6. Click OK.

You'll now see a new Top 10 Customers by Sales field in your Data pane under the Sets section. This set will dynamically update to always contain the 10 customers with the highest sum of sales, no matter how the underlying data changes.

Step 2: Create a Calculated Field Referencing the Set

Next, we will create our calculated field that uses the IN/OUT logic of the set to create our two new segments.

  1. Open the calculated field editor by clicking the dropdown arrow at the top of the Data pane and selecting Create Calculated Field.
  2. Name this calculation Customer Sales Segment.
  3. In the formula box, type the following:
IF [Top 10 Customers by Sales] THEN 'Top Customers'
ELSE 'Other Customers'
END
  1. Click OK.

This calculation is straightforward but incredibly powerful. Tableau looks at each customer. If the customer is "IN" our Top 10 Customers by Sales set, the calculation labels them as 'Top Customers'. If they are "OUT," they're labeled 'Other Customers'.

Step 3: Build Your Visualization

Now, you have a brand-new dimension you can use just like any other field in Tableau to build your analysis.

  1. Drag your new calculated field, Customer Sales Segment, from the Data pane onto the Rows shelf.
  2. Drag the Sales measure onto the Columns shelf.
  3. Drag Sales again onto the Label mark on the Marks card to display the sales values on the bars.

You now have a clean bar chart that compares the total sales generated by your top 10 customers against the sales from the hundreds of other customers in your database. This kind of segmentation, which took just a few clicks, would be much more cumbersome to achieve without sets.

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

Practical Examples of Calculations Using Sets

The "Top Customers" example is just the beginning. The same principle can be applied to countless analytical questions.

Example 1: Isolating Sales Within a Set

What if you don't want to group everyone else? Perhaps you only want to see the performance of a specific group. Use a set to isolate the measure itself.

Imagine you have a set named High-Margin Products. To calculate the total sales only from these products, your calculation would be:

IF [High-Margin Products] THEN [Sales] END

When you use this calculation to get a grand total, it returns the sum of sales exclusively for products that are "IN" the set, ignoring everything else completely.

Example 2: Comparing Proportions Using LOD Expressions

Let's get a bit more advanced. Suppose you want to know what percentage of each region's total sales comes from your top-selling product. First, identify the most profitable product and create a 'Most Profitable Product' set. Then use a calculation with a Level of Detail (LOD) expression:

SUM(IF [Most Profitable Product] THEN [Sales] END) / SUM({FIXED [Region] : SUM([Sales])})

This calculation first finds the sales derived specifically from your high-ticket item, then divides it by the total sales for the region it belongs to. When viewing by Region, this provides you with the exact proportion of each region as your profit engine.

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.

Using Combined Sets in Calculations

Tableau's power grows considerably when you realize you can create combinations of existing sets. Think of them as Venn Diagrams. If you have two different sets (e.g., "[Returning Customers in CA]" and "[Customers on our Holiday Mailers]"), you can right-click to select and merge both of them to choose whether you want all the participants from both or just specific ones.

  • Union: Includes all members from both sets.
  • Intersection: Includes only members that exist in both sets.
  • Difference: Includes members from the first set but not the second. (For example, Returned Customers in California but not on our Holiday mailing list.)

The resulting combined set is a new one in its own right - your existing set used as a calculated field to power extremely advanced and segmented analysis.

Using a combined set means you handle multiple dimensions directly, providing the most direct solution without needing to add filters (yet!).

Final Thoughts

Ultimately, using sets in calculations moves you beyond simple filtering and into the realm of dynamic, responsive segmentation. By leveraging the IN/OUT logic, you can group customers, products, regions, or any other dimension on the fly, creating new layers of analysis to expose insights that would otherwise remain hidden within the raw data.

Of course, mastering tools like Tableau involves a pretty steep learning curve. Sometimes, you just need a straightforward answer without remembering how to create sets, write IF/THEN logic, or build advanced calculations. We built Graphed for precisely this reason. By connecting all your sales and marketing data sources, you can ask questions in plain English - like "compare sales from my top 10 customers vs other customers" - and get an interactive, real-time dashboard built for you instantly, skipping the manual setup entirely.

Related Articles