In a recent post, C. Palo has asked for a "top N and others" solution. There is a KB article on the subject. But it's based on sets, which won't work for C. Palo because she has a few filters. So the top N will be dynamic while sets based approach only provides static top N, regardless of filters.

I would present here a tutorial on the topic. It is based on an approach by Tableau Zen Master Richard Leeke while using a different filter. Also would I explain some of the intricacies. This approach works on filtered results if any.

The example uses the superstore data set where we will show the top N countries with the highest sales, and group the others in a single bar.

Step 1. Create an integer parameter [Top N]
Step 2. Drag [Country / Region] to Details shelf and sort it by Sum(Sales) in descending order.
Note that all the 4 calculated fields below need to be set to compute using  [Country / Region].

Step 3. Create an Index: Index()
Turn it into discrete and drag it to Rows. Set it to compute using [Country / Region]. This index is mainly for the ordering of the results in final presentation.

Step 4. Create a [Top N+1 Rows] filter:
  • Index()<=[Top N] +1
Drag it to Filters and set it compute using [Country / Region]. Select True at pop up.

We only need N+1 rows/bars/marks in the chart. There comes the filter. The (N+1)th row will show "Others" with its aggregated value.

Step 5. Create [Top Countries & Others]. This will alias the country at the (N+1)th position to be "Others". Drag it to Rows and set it to compute using [Country / Region].
  • If Index()=[Top N] +1
  • Then "Others"
  • Else Attr([Country / Region])
  • End
Step 6. Create [Top Sales & Others]. At the (N+1)th position, the value is altered to be an aggregated result. Drag it to Columns and set it to compute using [Country / Region].
  • If Index()=[Top N] +1
  • Then Window_Sum(Sum(Sales),0,Last())
  • Else Sum(Sales)
  • End
Note that in the above formula, the If statement sets the index=0 for the window function which has its own index. The settings here instructs the window function to compute from (N+1)th row to the last row.

The aggregation at the (N+1)th row can be the average of all the others if you wish:
  • Window_Avg(Sum(Sales),0,Last())
We are done with a basic "Top N & Others" bar chart with grouping all others in one bar. Note that all table calculations have to compute using [Country / Region].
Dress up

Add a few extra steps to make the presentation better.

- Drag [Top Sales & Others] to Label/Text shelf and set it to compute using  [Country / Region].
- Create [Others] to color Top N and Others differently. Set it to compute using  [Country / Region].
  • Index()=[Top N]+1
- In Step 5, add a little calculation to show # of countries in the "Others".
  • If Index()=[Top N] +1
  • Then Str(Size()-[Top N])+" Others
Here is the final result. The workbook can be downloaded here.
If you want to have the option of expanding the countries in "Others", you can use a method proposed by another Zen Master Joe Mako.

Grouping Others per Category

The above approach can be applied to "Top N and Others" per category. Here is an example based on a question in the Tableau forum. It includes both a bar chart and a cross tab. This is an alternative solution to the one proposed by Zen Master Joe Mako.

An important change is using Rank_Unique(Sum(Sales)) for indexing, instead of Index(). This is based on an approach described in an early article.

Make sure all the table calculations in this example to be set to compute using Category.
Top N & Grouping Others Series
0

Add a comment

(Refresh the page if you want to view the gif image multiple times. Or go to Tableau Public and click the button at the top-right corner.)

Jake and I collaborated on a dashboard. He told me that he learnt a way to create an in-place help page in Tableau. He first saw it at a conference somewhere and couldn't recall who the speaker was. So I am blogging here about it but the credit goes to somebody else. If anyone knows who the original creator is, leave a comment below.

The key idea is to float a semi transparent worksheet on top of the dashboard, where a help text box is strategically placed on top of each chart. This way, we can explain how to view each chart and what data points are important, etc. This worksheet is collapsible by a show/hide button. 

Below I would like to show how this worksheet can be constructed.

1. Sheet with a single data mark.

  • Double click the empty space in Marks panel and add two single quotes. Make the null pill a text label. This creates a single null mark.
  • Set the view as "Entire View"

2. Create an show/hide button

  • Go to the target dashboard
  • Drag a floating vertical container to the dashboard, making it cover all the area of interest.
  • Drag the Single Null Mark sheet and drop it into the above container. Hide the sheet title.
  • Create an open/close button for the container and place the button at the top-right corner.

3. Add annotations

  • Format the sheet background opacity as 70% in the layout manager             
  • Select area annotations and place them anywhere of interest. 
  • Write help text and format it to highlight important messages.  
  • The text can serve as functional guide and/or insight guide.

Here is an example. Feel free to download the workbook and explore. Click the "i" button at the top-right corner to view the in-place help. 

0

Add a comment

Blog Archive
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.