How to Create Top N Parameter in Tableau

Cody Schneider••6 min read

Showing your top 5 products by sales is easy, but what happens when your manager wants to see the top 10? Or the marketing team only cares about the top 3? Going back to edit your Tableau workbook each time is a slow, repetitive process. The solution is to create a dynamic "Top N" filter using a parameter, letting anyone viewing the dashboard choose the number of results they want to see on the fly. This article will walk you through exactly how to set that up from start to finish.

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

First, Why Use a Parameter?

You might know that you can quickly show top performers in Tableau by simply dragging a dimension (like Product Name) to the Filters shelf and using the built-in "Top" tab. You can set it to show the Top 10 by Sales and call it a day. This is a static filter. The "10" is hard-coded, and if anyone wants a different number, they can't change it without editing the workbook directly in Tableau Desktop.

A parameter, on the other hand, is like a variable that you, the creator, define and the end-user can control. By creating a parameter for your number (the "N" in "Top N") and linking it to your filter, you give your audience an interactive control element - like a dropdown menu or a slider - directly on their dashboard. This small change transforms a static report into a flexible, self-service analysis tool.

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: Build Your Basic Visualization

Before you can filter anything, you need a view to work with. For this tutorial, we'll use the Sample - Superstore data source that comes with Tableau. We'll create a simple horizontal bar chart showing sales by product sub-category.

  1. Connect to the Sample - Superstore data source.
  2. Drag the Sales measure to the Columns shelf. This will contain the values we'll use to determine the "top" performers.
  3. Drag the Sub-Category dimension to the Rows shelf.
  4. Click the Sort Descending button in the toolbar to arrange the bars from highest sales to lowest.

At this point, you should have a simple sorted bar chart showing all 17 sub-categories, with "Phones" and "Chairs" at the top.

Step 2: Create the "Top N" Parameter

Now we'll create the control that allows users to pick their own "N." This parameter will hold the number - 5, 10, 15, etc. - that our filter will eventually use.

  1. In the Data pane on the left, right-click any empty space and select Create Parameter.
  2. A configuration window will pop up. Let's fill it out field by field:
  3. Once you're done, click OK.

You'll now see "Select Top N" at the bottom of the Data pane under a new "Parameters" section. To make it visible so users can interact with it, right-click on the new parameter and choose Show Parameter. A small interactive control box will appear on the right side of your worksheet.

Important: At this stage, the parameter is visible, but it doesn't do anything yet. Playing with the slider won't change your chart because it isn't connected to anything. That's our next step.

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 3: Connect the Parameter to a Filter

This is where we connect the user's input with the data displayed in the chart. We will add a filter on our dimension (Sub-Category) and tell it to use our new parameter for its logic instead of a fixed number.

  1. From the Data pane, drag the Sub-Category dimension onto the Filters shelf.
  2. The Filter dialog box will open. In this window, navigate to the Top tab along the top.
  3. Select the option By field.
  4. By default, it prompts you to choose "Top [ 10 ] by [ Sales ] [ Sum ]." We want to replace the hardcoded "10" with our parameter.
  5. Click on the dropdown menu where it says "10." You'll see your newly created "Select Top N" parameter at the bottom of the list. Select it.
  6. Ensure the rest of the options are correct. In this case, we want the top performers based on the Sum of Sales.
  7. Click OK.

Your chart will instantly update to show only the number of sub-categories specified by the parameter control (in our case, the Top 10). Now, try it out! Use the slider or type a number into the parameter box on the right. The chart will dynamically update to show top 5, top 12, or whatever number you choose. You just turned a static report into an interactive tool!

Going Further: Bonus Tips for a Clean Dashboard

Create a Dynamic Chart Title

To make your chart even clearer, you can make the title update based on the parameter's value. Instead of a static title like "Sales by Sub-Category," you can make it say "Top 10 Sales by Sub-Category" and have the "10" change automatically.

  1. Double-click the title of your chart.
  2. In the "Edit Title" dialog box that appears, edit the text to be something like "Top N Sales by Sub-Category." Place your cursor right after "Top."
  3. Click the Insert button dropdown and select your parameter, <Parameters.Select Top N>.
  4. Click OK.

Now, as you adjust the parameter slider, your chart title will update to reflect the selection, which adds helpful context and a professional polish for the end-user.

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.

Grouping "Everything Else"

A Top N filter is great, but sometimes it's also helpful to see the 'rest' aggregated into a single "Other" category. You can accomplish this with a combination of a calculated field and a set.

1. Create the Set

  • In the Data pane, right-click the Sub-Category dimension and select Create > Set.
  • Give the set a name, such as "Top N Sub-Category Set".
  • Move to the Top tab and configure it in the same way we did for the filter: Top <Parameter> by Sales with Sum as the aggregation.

2. Create a calculated field

IF [Top N Sub-Category Set] THEN [Sub-Category] ELSE "Other" END

This field will check if any sub-category is in the set we created. If it is, it will show the sub-category name, if not, it will show "Other".

3. Use the New Calculated Field

  • Drag the calculated field from the Measures pane to the Rows shelf and remove the original Sub-Category.

Now your chart will display the Top N performers together with "Other" in one comprehensive view.

Final Thoughts

You have successfully transformed a static Top N chart into an interactive visualization, giving users control over how they view data by setting up parameters and eventually using calculated fields. This way, you create dashboards that not only cater to individual user requests but also empower team members by allowing them to answer their own questions without needing technical guidance.

When it comes to visualizations in Tableau, they're not just beautiful, they're powerful when built correctly. At Graphed, we believe in harnessing that power to build insightful, data-driven dashboards that empower your team to make informed decisions.

Related Articles