3 Replies Latest reply on Nov 15, 2016 7:45 AM by michelle.smith.2

# Struggling with filtering for top 5

I'm trying to get Tableau to only show the top 5 based on the amount in the last 12 month period.  In the example in the Trend Graph sheet, the graph shows a trend of the 12 month look back period during 2013 (so Jan 2013 really represents the sum of sales from 2/1/12 - 1/31/13).  I have the data sorted correctly using the SortStateField calculation, but I can't figure out how to get Tableau to only show the first five.  the SortStateField is using a Window_Sum calculation, and I cna't seem to filter on that.  Any help would be greatly appreciated!!

• ###### 1. Re: Struggling with filtering for top 5

Hi Michelle,

Unfortunately, I'm not able to open your example, but you can try something like this:

Create a calculation to Rank your states field by the sum of sales (or which ever measure):

rank(sum([Sales]),'desc')

Place the pill on your columns shelf, then convert it to discrete.

Next, create a calculated field to filter your Rank pill to the top 5:

if [Sort by Rank]<6 then 1 else 0 end

Place this pill on the filters shelf, then filter to 1.

See the example below/

Hope this helps.

Don

• ###### 2. Re: Struggling with filtering for top 5

Hi Michelle,