course bg
EduPristine>Blog>Top N analysis with Tableau

Top N analysis with Tableau

January 7, 2016

Every dashboard or chart created needs to support one common business question which is “What are the Top (or bottom)
N (replace N with 5, 10 etc.)
Products (it can be anything Geo, Channel, Customers etc.)
by Revenue (it can be anything Profit, Margin % etc.)?”
In this blog, we are going understand how to answer this question with the help of filters and parameters.

In this blog we will use cricket data to understand how to do Top N analysis with the help of filters and parameters. In the process we will also understand what a context filter is.


The data can be sourced from and formatted appropriately for Tableau’s consumption. This is the first important and often time-consuming step before data visualization and exploration can happen. We have batting data for One Day International (ODI) matches played between years 1971 to 2011 with close to 60,000 data points. The below table gives you a quick overview of important dimensions and measures present in the dataset.

Dimensions Measures
Country Runs
Player name Score Rate (runs per 100 balls faced)
Opponent country  
Match Date  

Data Exploration & Visualization

For this article our analysis is going to be around who are the Top N batsmen in terms of run scored.

Step 1 – Connect to the data.

connecting data to tableau

Step 2 – Go to Sheet 1 and analyse/review the loaded data.

reviewing data

Step 3 – Place Players on Row shelf

placing values  in row shelf in tableau

Step 4 – Place Runs with aggregation method as SUM on column shelf

placing values  in column shelf in tableau

 Step 5 – Sort on Runs

sorting values  in tableau

Now this is the crudest way of getting the list of Top N list of players who have scored the highest runs. The problem with this approach is that one sees all the players in the visualization and how one can restrict the visualization to show just top 5 or 10 or 20 players who have scored the most runs.

Step 6 – Put Filter on Player

Filtering data  in tableau

Filtering data  in tableau

Apply Top Filter on Player by Field Runs with aggregation method as Sum as shown above to get top 10 players by sum or runs.

The result of applying filter is as shown below with list of Top 10 players who have scored the most runs. As one can see Sachin Tendulkar tops the chart with no marks for guessing followed by Ricky Ponting, Jaysuriya and so on. Please note that this ranking is based on data of matches played till 2011. We have partially achieved what we wanted to do in terms of Top N analysis. How do one can make N vary and give the control of changing in the hands of a user. Let us say if one wants to find the list of Top 5 or 10 or 20 players by runs then the mechanism available in Tableau is to resort to parameter.

top N analysis  in tableau

Step 7 – Create a parameter

creating  parameters in tableau

Create a parameter of type integer as shown above and choose to show it. Note that the changing the value of parameter on top right (as shown below) will not have any impact on visualization as yet.

creating  parameters in tableau

 Step 8 – Use parameter in Filter

using parameter  in filter in tableau

Choose the parameter (Top N Input) that we created in above step in the filter as shown in the image above. Note that we could have created a parameter from the option provided in this dialog box.

Step 9 – See the parameter in action

parameters in  tableau

Changing the parameter value in slider will now change the visualization to reflect top N players by runs where N is determined by user selection through parameter control.

Step 10 – Put Country in Filter

filtering data  in tableau

Let us say we are interested in finding out Top N Indian Players by runs so put Country on Filter and select India as shown above.

After applying Country filter if one looks at the visualization (below) it just shows Sachin Tendulkar whereas parameter is set to 5. That is the visualization should have shown top 5 player of India who have scored the most runs.

filtering data  in tableau

Step 11 – Add Country Filter to context

filtering data  in tableau

The result of applying country as context filter now correctly produces visualization to show Top 5 batsmen of India by runs.

Top N analysis  in Tableau

A context filter is applied to the data source first, and then the other filters are applied only to the resulting records.

So take away from this blog are as below

  • Using Filter’s Top/Bottom condition by field and aggregation method
  • Using Parameter with Filter
  • Using Context Filters

That is it for this time; stay tuned for more learning with Tableau.

About Tableau

Tableau (NYSEDATA) headquartered in Seattle, Washington has a mission to help people see and understand data. It offers a product portfolio for data visualization focused on business intelligence.

One can visit the official Tableau website to find more details about Tableau and its product offering and features.

About Author

author pic EduPristine

Trusted by Fortune 500 Companies and 10,000 Students from 40+ countries across the globe, it is one of the leading International Training providers for Finance Certifications like FRM®, CFA®, PRM®, Business Analytics, HR Analytics, Financial Modeling, and Operational Risk Modeling. EduPristine has conducted more than 500,000 man-hours of quality training in finance.


Interested in this topic?

Our counsellors will get in touch with you with more information about this topic.

`````````````````````````````````````````````````` Post ID = 87100