After finishing Grouping Lower % Slices in Pie Chart, I feel it is necessary to write a companion post about the bar chart counterpart. Bar chart is still the most popular chart type of all time. Tableau Zen Master Joe Mako wrote a post on grouping low ranked bars into one, which is great inspiration to me.

I will use the same data in pie chart example which makes things easier. The statement of the problem is how to group the lower % bars into a single one after a sorted measure. In the example, we need to group those lower % sales countries into a single label: "Others".

Create the Bar Chart

1.Create a parameter [N% Chooser] which allows us to choose any % as threshold. Show the parameter control. One can skip this if the percentage is a given number.
2.Create a new field [Top % + Others Label] which labels all low % slices as "Others". Drag it to the Row shelf. Note that the percentage is dynamically controlled by the parameter 0.01*[N% Chooser]. One can replace it by a given number if necessary.
3.Drag the [Country/Region] to the Detail shelf. 

4.Create a new field [Top % + Others Sales] which sums up the sales of all Others into one value. We will explain the logic later. Drag it to the Column Shelf. Right click the pill and select Compute Using>Country/Region.
Now we got a barebone bar chart with an "Others" bar. Dressup is in order and will be done next.
Dress Up

- Click the descending sort button to sort the bars.

- Click the "42 nulls" at the down-right corner and you will see a pop up. Click Filter Data to get rid of the Nulls. A green pill will appear in the filter shelf.
- Create [Percent] field and drag it to the Label shelf. Right click on it and select Format to make the numbers in %.
  • [Top % + Others Sales]/Total(Sum([Sales]))
Now we are essentially done. Further cleanup is recommended:

- Create a [Is Top %] field as follows. Drag it to the Row shelf and place it before [Top % + Others Label]. In the table, drag True to above False. Then right click it to uncheck Show Header.
  • [Top % + Others Labels] !="Others"
- Drag [Is Top %] to the Color shelf. Now the "Others" bar is at the bottom of the chart with a distinct color.

- Right click the horizontal axis and uncheck "Show Header".

- Right click the canvas and select Format. Go the grid menu and turn both Row and Column Divider to None. This will remove some unnecessary horizontal and vertical lines.
And it's done! The workbook can be found here.

Calculating [Top % + Others Sales] and Filtering

To help understand the calculation, we attached a table in the above workbook. The table values are sorted descendingly according to sales. We see that all the lower % countries are labeled with "Others". And only the last country in "Others" has values. The rest of countries have Nulls.

The calculation is as follows:

if [Top % + Others Labels]="Others"
then if Last()=0
     then Window_Sum(if [Top % + Others Labels]="Others" then Sum([Sales]) end)
     end
else SUM( [Sales] )
end

It shows that, for the new label "Others", we need a different calculation. Otherwise it's just Sum([Sales]).

Widow_Sum() will only sum up the sales of those countries labeled with "Others".

We only need one value which sums up all the "Others". Last()=0 will do that. The rest is filtered out.

Voila!

3

View comments

(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.