I almost named the post as Charting "Top N and Others" via Post-filtering. Read on to understand why.

Visualizing "Top N and Others" is an often required business use case. A popular solution is by creating a top N set. That's the one I have been using through the years.

I wrote a post in the context of a pie chart back in 2014 on grouping those smaller slices into 'Others'. 

Recently, I encountered an issue at work. The dashboard won't let me using set. The problem with this set-based solution is that "set" is a filter operating before the regular dimension filters. We may want the dimension filters to execute before the set. This can be done by adding the dimension filters to context. In a multi-sheet dashboard, this may impact calculations on other sheets when a cross-sheet filter is applied, where the dimension filters may not be allowed to be in context.

There are almost always two ways to skin a cat in Tableau: Pre-filtering and post-filtering.

Pre-filtering: Filter the data set and keep only the data we need. This works with dimension filters, set filters, context filters etc.

Post-filtering: Filter the calculation results and keep the results we need. This works with table calculation filters.

Here we are going to show a table calculations approach to solve the problem. Table calculations filtering takes place in the last stage in Tableau's order of operations. So it works after the regular dimension filters. This is a post-filtering approach.

We are going to show our approach using the superstore data set and chart sales in top N states plus all others in one bar.

First let's create an integer Top N parameter. And have the State dimension is sorted by SUM(Sales).

Then create a formula for Label Grouped which includes the top N states plus "All Others".

Third, create a formula for Sales Grouped where all sales beyond top N states are grouped in a single quantity.

Last, create a top N+1 index filter for keeping the top N+1 bars.

The resulting chart looks like this:
Make sure that all the table calculations are computed along State.

Voila, the demo workbook can be downloaded from here.
0

Add a comment

[Forward: I asked ChatGPT o1-mini who then wrote this. Hope it helps. All the credit and the blame go to ChatGPT.

I went over the plan and it looked decent. Whether it can be done in 30 days or not, it depends on the person and the time he spends on it.
Just came back from Tableau Conference 2022 at Las Vegas. What an exciting event! The most exciting thing is reuniting with old friends and meeting with the datafam people known online for years.

Attended first time the Tableau Visionary summit.
A little enhancement in the formula editor can make a big difference for whose who create formula all the time in Tableau. Here are my wishes for a future editor. 

Highlighting Syntax Words

Currently a formula in Tableau can look plain and a bit uninspiring.
Blog Archive
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.