How to Show Top N Results in Tableau Chart

While analyzing sales performance across the country, our management team wanted to identify the Top 10 states contributing the highest sales. Instead of reviewing data for all 50 states in the USA, they only needed to focus on the states that generated the most revenue in sales.

By creating a chart in Tableau that shows the top States by Sales, we could highlight the states with the highest sales and compare their sales contribution.

In this tutorial, I will explain how to show the top N results in a Tableau chart using the various methods.

Show Top N Results in Tableau Chart

In Tableau, there are three ways to display the top n results in the Tableau charts.

  • Show top N results in Tableau using filters
  • Show top N results in Tableau using parameters
  • Show top N results in Tableau using rank calculation

Show Top N Results in Tableau Using Filters

In this example, we will create a bar chart that displays sales for the top states. To do this, connect the Tableau Superstore dataset and follow the steps below.

  1. Select the dimension in which you want to filter the top records and drag it to the filters. In this example, I will use ‘State/Province‘.
  2. In the filter window, click on the Top tab. After this, select By field -> Sales. After this, select ‘Top 10’ and click ‘OK’.
Show top 10 results in Tableau chart
  1. Press the “Ctrl” key and drag the states from the Filter to the Rows. With this, we will get the filtered states on the chart.
Create a Tableau chart with top 10 results
  1. To show the sales for each state, drag the Sales to the Columns.
Create Tableau chart with Top N results
  1. To sort the sales in ascending or descending order, click on the sort button in the navigation bar.
Sort top n results in Tableau chart
  1. To show the sales values for the top 10 states, drag the sales to the Label card in the Marks section.
Create a Tableau chart with top n results

Now, we can see the sales of the top 10 states in the Tableau chart, arranged in descending order.

This way, we can filter the top ‘n’ records in Tableau by using the filters.

Show Top N results in Tableau Using Parameters

Another way to show the top “N” results in Tablesu is by using the parameters. In this method, we can dynamically change the number of filtered records and display them on a chart.

In this example, using the Tableau Superstore dataset to show the profit for the top 5 product subcategories.

Connect the Tableau with the Superstore dataset and follow the steps below.

  1. To create a parameter, click on the dropdown near the search bar and select Create Parameter.
Display N number of records using parameter in Tableau
  1. Enter the parameter name, such as “Top Dimension,” and select the Data Type as “Float.” Then, in the Current Value, select the records you want to filter and click the OK button.
Filter N records in Tableau charts
  1. After this, drag the dimension (sub-category) to the Filters. In the filters, select the Top tab, then select “By field” and chooseProfit“. Then, in the “Topsection, select the “Top dimension” parameter and click OK.
Show N number of records in Tableau Chart
  1. Now, hold the “Ctrl” key and drag the dimension “Sub-Category” from the filter to the Rows. After this, add the ‘Profitmeasure to the Columns. With this, we will get the top records for the Current value (10) we have entered in the parameter.
Show only top 10 records in Tableau
  1. Sort the order from the sort button in the navigation bar and add the Profit to the Label card in the Marks section.
Ranking top n records in tableau
  1. To change the top “n” numbers dynamically, click on the parameter “Top Dimension” in the side bar and select Show Parameter.
Show only top 10 results in Tableau bar chart
  1. Now, on the right side of the chart, we will see the parameter Top Dimension. From here, we can change the number of top “N” records, and as we refresh the chart, the same number of top records will be displayed on the chart.
Filter Top N records in Tableau

This way, we can dynamically filter the top “n” records in a Tableau chart using the parameters.

Show Top N results in Tableau Using Rank Calculation

In this method, we will create a calculated field for rank calculation to display the top N records in the Tableau chart. In this chart, we will display the sales for the top states using the Superstore dataset.

  1. Right-click in the Data PaneCreate Parameter and add the following details.
    • Name: Top N.
    • Data Type: Integer.
    • Current Value: 10.
    • Select Range, and add the minimum and maximum values of the range.
    • Click OK.
Show Top N results in tableau chart
  1. Create a calculated field with the label Index Filter and enter the formula below. This formula will filter the top n results using RANK.
IF RANK(SUM([Sales])) <= [Top N] THEN
    "Show"
ELSE
    "Hide"
END
  1. Now, drag State to Rows and Sales to Columns.
Use calculated field to show Top N records in Tableau
  1. Drag the calculated field to the Filters. Then, in the Filter, select the Show checkbox and click OK.
Display top N results in Tableau chart using Rank
  1. To dynamically change the top “N” numbers, click on the parameter Top N and select Show Parameter.
Tableau Chart Show Top N results
  1. Now, we can see the “Top N” parameter on the right side of the chart, from which we can dynamically change the “N” value to display the top “N” results.
Show top N results using rank in Tableau

As we change the parameter digit, the same number of top results will be displayed in the Tableau chart.

This way, we can show the top N results in Tableau using rank calculation.

Conclusion

In this Tableau tutorial, we learned how to show the Top N results in Tableau in three simple ways. In the first method, we used filters to display the top 10 records. Then, in the second method, we used parameters to make the chart dynamic, allowing users to change the number of top records.

Then, in the last method, we used a rank calculation to get more control in displaying the top n results. Using these methods, we can highlight key information, such as the top states by sales or any other measure comparison for top dimensions.

You may also like to read:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.