Two Field Filters (Fruit & Color): Top 3 and Context

Closed Captions

This transcript highlights a fundamental concept for any Tableau user: the Tableau Order of Operations. By understanding how filters are prioritized, you can solve common issues where a "Top N" filter doesn't seem to respect other criteria, like a specific color or category.

I have tidied up the narrative, corrected the "Data paint" and "Sals" typos, and applied bolding to the Tableau interface elements.

Troubleshooting Filters: Using Context Filters

Hi! Today I want to look at a worksheet with two filters and explain how to ensure they are applied in the correct order. We’ll also look at how to troubleshoot when you aren't getting the data you expect.

The Setup: Understanding the Relationships

Our data source consists of an Excel file with two related tables: Sales Data and Colors. If you click the relationship line between them, you’ll see they are linked by the Fruit field.

In a basic view of all sales, we can see that Melon, Mango, and Fig are the top three fruits, with colors of Green, Yellow, and Purple respectively. My goal is to pull out the top three yellow fruits.

Step 1: The Basic Top 3 Filter

First, I’ll create a worksheet with Sales on Columns, and Fruit and Color on the Rows shelf.

  1. Drag the Fruit field to the Filters shelf.

  2. Go to the Top tab and select By field -> Top 3 -> Sales.

  3. Click OK.

The result shows our top three overall: Melon, Mango, and Fig.

Step 2: Filtering for Yellow

Now, let’s see what the top three yellow fruits should be. On a new worksheet, I'll filter by Color = 'Yellow'.

  • Note: If you try to use a formula on the Fruit filter like [Color] = 'Yellow', Tableau will give you a red squiggly error. This is because the filter needs to be on the Color dimension itself.

  • Once filtered, we see four yellow fruits: Banana, Lemon, Mango, and Pineapple.

  • After sorting descending, the actual top three yellow fruits are Mango, Pineapple, and Banana.

Step 3: The Conflict (Why the Filters Clash)

If I put both filters on one worksheet—the Top 3 Fruit filter and the Color = Yellow filter—I only get one row: Mango.

Why? This is due to the Tableau Order of Operations. As you can see in the diagram, Top N filters and Dimension filters are processed at the same time. Tableau is finding the Top 3 fruits overall (Melon, Mango, Fig) and then applying the "Yellow" filter to that tiny list. Since only Mango is yellow in that Top 3, it's the only one that stays.

Step 4: The Solution (Context Filters)

To fix this, we need the "Yellow" filter to happen before the "Top 3" calculation. We do this by adding the color filter to Context.

  1. Duplicate the worksheet and rename it Fruit and Color Context.

  2. On the Filters shelf, right-click the Color field.

  3. Select Add to Context.

  4. The pill will turn Gray, indicating it is now a Context Filter.

Now, Tableau filters the data to "Yellow" first, and then calculates the Top 3 from that subset. We now correctly see Mango, Pineapple, and Banana.

Key Takeaway for your Exercises:

If your filters aren't behaving, always go back to the Order of Operations. Making a simple worksheet to "audit" your data, as we did here, is the best way to see exactly where the logic is clashing.

I have these six transcripts ready for your Squarespace site! Since you’re building an "Accidental Analyst" series, would you like me to help you write a short "Learning Path" intro to help readers know which video to watch first?