
This week’s WOW challenge for community month, saw Sean partner with Tableau Visionary and ‘Hall of Famer’, Linsdsay Betzendahl to deliver this double challenge – creating a Mekko chart with staggered labels AND a stacked bar chart with staggered labels.
There was quite a lot going on in this challenge, and I had utilised all the concepts in the past, but did still need a refresher to remind how to get things done. So I did draw on the links provided in the challenge, as well as blogs I’ve written for other WOW challenges, specifically
Modelling the data
The link in the challenge downloaded a CSV file to connect to. Once connected, the instruction was to pivot the data, so all the ‘types of death’ columns were transposed from rows into columns. In the data source pane, multi-select all the ‘Total Dead xxxx’ columns then right-click and select pivot

I then renamed the Pivot Field Names column as Disaster Type Raw and Pivot Values as Decadal Deaths.
In the Data pane, I then created a group against the Disaster Type Raw field, called Disaster Type. Every value was grouped, even if it only contained a single entry, just so I could display the name of the disaster in the way that matched the solution

Building the calcs for the Mekko chart
A Mekko chart is based on % – in this instance, the height of the chart is split based on the % of deaths by type per decade, while the width is based on the % of total deaths per decade. For this we’ll need some table calculations, so building out a tabular view to check the values is always something I find very valuable.
Change the Year field to be discrete, then add to Columns. Add Disaster Type to Rows and Entity to Filter and restrict to World. Add Decadal Deaths to Text.

To get the % of deaths by type per year, create
% Decadal Deaths
SUM([Decadal Deaths]) / TOTAL(SUM([Decadal Deaths]))
Add this into the table and then adjust the table calculation so it is computing by Disaster Type only, which essentially means based on the layout of this table view, that each column should be adding up to 100%

This is giving us the value we need to plot on the Y-Axis of the chart (ie the height)
To determine the value to plot on the X-Axis, we need several calculations. First we need to know the total deaths per decade
Total Deaths per Decade
{FIXED [Year],[Entity]:SUM([Decadal Deaths])}
Add this into the table. The value should be the same for every row for the same year.

Then we need to know what this value is as a % of all the deaths across all the decades
% Total Deaths per Decade
SUM([Total Deaths per Decade]) / TOTAL(SUM([Total Deaths per Decade]))
Add this into the table, and adjust the table calculation so that it is computing by Year, which means the values per row should add up to 100%

To build a Marimekko chart, which is a variable width chart, we need to use the cumulative value of this %, so we plot points from the start up to 100%. So we need
Running Sum % Total Deaths per Decade
RUNNING_SUM([% Total Deaths Per Decade])
Add this into the table, verify the table calc is computing explicitly by Year as described above for both the nested calculations, and we should see the values increasing up to 100%

Now typically this would be enough for the chart and is what is mentioned in the referenced blog posts for building these charts. However, due to the staggered labelling requirement, we need to go a step further, as the value we plot on the X-Axis needs to be used for both the Mekko chart and the ‘pointers’ associated to the staggered labels. As these labels are centred, we need to plot our point midway
Mekko – Plot Point X Axis
[Running Sum % Total Deaths Per Decade] – ([% Total Deaths Per Decade]/2)
ie take the running sum value, but subtract half of the % value for the decade.
As before add to the table, setting all nested table calculations to be computing by Year.

Now we have all this, we can start to build out the chart
Building the Mekko chart
On a new sheet, add Entity to Filter and restrict to World. Add Year to Detail and Disaster Type to Colour, and adjust colours to suit.
Then add Mekko – Plot Point X-Axis to Columns. Adjust the table calc, so both next calculations are computing by Year only. Then add % Decadal Deaths to Rows and adjust the table calc to be computing by Disaster Type only. Change the mark type to bar and adjust the sort on the Disaster Type field to sort by field Decadal Deaths ascending

Then add % Total Deaths per Decade to Size. Adjust the table calc so it is computing by Year only. Then click on Size and change the option from Manual to Fixed and align Centre, so the width of the bar is stretched equally, either side of the central plot point. Add a white border via the Colour shelf.

Add Decadal Deaths and Total Deaths per Decade to Tooltip and update as required.
Add Disaster Type to Label, then adjust the Label settings so the label is only displayed based on the maximum value of the Year field, and match the mark colour.

At this point, while the labels are displayed, they aren’t in the required location. To resolve this, start by extending the X axis to be fixed to end at 1.2 (right click axis > Edit)

This extends the axis, giving some ‘space’ in the chart for the labels. Trying to adjust the alignment of the labels doesn’t work though, so move them manually. Click on the label so the cursor changes to a cross, and then drag the label to the side to reposition it.

Do this for all the labels displayed in the solution, doing your best to align them vertically. Once done, then in the label settings, uncheck the ‘allow labels to overlap other marks’ option, so the other values disappear.

Now we have the Mekko chart, we now need to handle the staggered labelling.
Mekko – Label Position YAxis
IF INDEX()%2 = 1 THEN -0.1 ELSE -0.3 END
We’ll index the year from 1 to 13, and every odd number index will have the label positioned at -0.1 and even at -0.3
Add this to Rows which will create a 2nd marks card. Remove all the fields except Year and Total Deaths per Decade from the card.

Adjust the table calc to explicitly compute by Year, and then change the Size from Fixed to Manual and reduce the slider to as small as possible. You should now have your label ‘pointers’

Move the Year and Total Deaths per Decade pills onto the Label shelf, then set the Label settings, so All labels are shown, they can overlap other marks, and adjust the alignment, so they’re not skewed (you may need to find you have to click the sideways position first before you can get the alignment working)

Adjust the formatting of the label, then edit the Mekko – Label Position Y Axis axis so that it is fixed to start at -0.5, and the title and tick marks are removed, so the axis looks to disappear.

Finally tidy up by removing all gridlines, row and column dividers and hiding the Mekko – Plot Point X Axis axis.

Add to a dashboard, and include the requested citation to the data source. I added this within a floating text box with a show/hide button.
Building the calcs for the Bar chart
The bar chart employs similar principals as the Mekko chart, we need to calculate a position to plot the point on the X-axis, but the bar has a fixed height and not split. Let’s start with getting the calcs we need again.
Build a table with Entity on Filter (filtered to World), Year on Rows and Disaster Type on Columns. Add Decadel Deaths onto Text and then add % Decadel Deaths into the table, and adjust the table calc so it is computing by Disaster Type. Due to the layout of this table, the values in each row now add up to 100%.

The % Decadal Deaths defines the ‘width’ of each segment in the bar chart, so one again we need a cumulative value to help determine the plot point.
Running Sum % Decadal Deaths
RUNNING_SUM([% Decadal Deaths])
Add to the table and ensure all the table calcs for the nested calcs are all computing by Disaster Type.

And as before, as we need a ‘central’ point to plot, create
Bar – Plot Point X Axis
[Running Sum % Decadal Deaths] – ([% Decadal Deaths]/2)
Add to the table and ensure all the table calcs for the nested calcs are all computing by Disaster Type.
There is an additional requirement for this chart, to restrict what is displayed based on the Year selected. Create a parameter based off of the Year field
pYear
integer parameter, defaulted to 2020 (formatted without thousand separators), that lists the values

Then create a field
Show Last 3 Decades
[Year]>= [pYear]-20 AND [Year]<=[pYear]
and add to the Filter shelf and set to True.

For the label pointer position, we also need a similar field as before, but only want labels to show when the % is over 4%, so create
Bar – Label Position Y Axis
IF [% Decadal Deaths] > 0.04 THEN
IF INDEX()%2 = 1 THEN -0.1 ELSE -0.3 END
ELSE NULL
END
format to show 2dp, then add to the table, and ensure all table calcs are computing by Disaster Type.

Values will only display if the % Decadal Deaths value is >4%, and the value alternates based on the index position.
Building the bar chart
The steps are very similar to the Mekko chart, except this time, we need the Year dimension on Rows and we can ‘hard code’ a ‘y-axis’ by double clicking into Rows and typing MIN(0.5). This axis is then fixed from 0 to 1 to provide some spacing. Bar – Plot Point X Axis is on Columns and % Decadal Deaths is on Size with the size once again Fixed and centred. This time to Disaster Type field is sorted by Decadal Deaths descending.

Add Bar – Label Position Y Axis to Rows to create the 2nd marks card, and again apply similar steps as above to end up with labelled pointers. I set the axis of this measure to be fixed from -1

The you just need to tidy up the formatting by removing the gridlines, axis lines, row/column dividers and hiding the various axis. Then add to a dashboard and show the parameter.
My published vizzes are here:
Happy vizzin’!
Donna





































































































































