
After a couple of weeks off due to holiday, it was my turn to set the challenge. When browsing around for inspiration, I came across this stem & leaf Power BI WOW challenge by Meagan Longoria, which in turn was inspired by a Tableau WOW challenge set by Yusuke in 2024.
So I thought it would be fun to go ‘full circle’ and see if I could recreate Meagan’s challenge in Tableau, which builds on Yusuke’s challenge, as this requires the ‘leaves’ to be spread across multiple rows.
Defining the calculations
The data set provided contains a rows uniquely identified by a Row ID, and each row defines a Species of Iris and the Petal length, which is a decimal number in cm.
To build the stem and leaf chart, we need to first identify the Stem and then the Leaf. If the length is 4.6cm for example, then the stem is 4 and the leaf is 6.
Stem
INT([Petal length (cm)])
Format this to a number with 0 dp and move to the ‘dimensions’ section of the data pane (above the line).
Leaf
INT(ROUND(([Petal length (cm)] – [Stem])*10,0))
Again, format this to a number with 0 dp and move to the ‘dimensions’ section of the data pane (above the line).
Note – Originally my function was INT(([Petal length (cm)] – [Stem])*10), but I found in some occasions this wasn’t given me the right values eg 4.1 was reporting a Leaf of 0, due to the precision of the original number stored. Using the ROUND function to convert the number to have 0 dp resolved this.
Put all these fields into a table like below, so we can start to sense check the other calculations we’ll need.

The final chart will plot the ‘leaves’ as points on an X and Y axis. The central ‘spine’ of the chart is where X=0, and the leaves are the plotted with the position based on the Stem value and then which row and column the leaf is in. Records associated to the Iris-versicolor Species will be plotted on the left side (negatives) while the Iris-virginica Species will be plotted to the right (positives).
The leaves need to organised into rows of 10 per Stem, per Species, sorted by the Leaf value (smallest first). To manage this, we first need to understand how many leaves are associated with each Stem and Species, and give them a ‘counter’ (ie index) per Stem/Species cohort.
Leaf Index per Stem
/*
For each stem per species, index the leaves from 1 to however many there are in the cohort.
*/
INDEX()
Add this into the table, and adjust the table calculation so it is computing by Leaf and Row ID only and add a Custom Sort by Leaf ascending

We now want to identify which ‘row’ (per stem) the leaf will sit on based on it’s index number. If there’s more than 10 leaves per stem, then we need to plot on multiple rows, where the row count starts at 1. Dividing Leaf Index per Stem by 10 will help us do this, but as all leaves indexed from 1-10 need to be on the 1st row, we need to subtract 1 from the index before we divide. We can then convert to a whole number with the INT function, but as we want rows to start at 1, we then need to increment.
Leaf Row Number
INT(([Leaf Index per Stem]-1)/10) + 1
Eg
Leaf Index = 4 -> subtract 1 = 3 -> divide by 10 = 0.3 -> apply INT function = 0 -> add 1 = row 1
Leaf Index = 10 -> subtract 1 = 9 -> divide by 10 = 0.9 -> apply INT function = 0 -> add 1 = row 1
Leaf Index = 11 -> subtract 1 = 10 -> divide by 10 = 1.0 -> apply INT function = 1 -> add 1 = row 2
Add this into the table and apply/verify the table calculation settings are as above.

We then want to identify which column each leaf should be in, which should be a number between 1 and 10 for Iris-virginica and -1 to -10 for Iris-versicolor. We can use the modulo (%10) function for this, based on the Leaf Index per Stem value, to find the remainder if the index is divided by 10. Similarly to before, as all leaves indexed from 1-10 need to be in the equivalent numbered column, we first need to subtract 1 from the index before we find the remainder, but then we need to add 1 to the final result, to get the desired result.
Leaf Column Number
(([Leaf Index per Stem] -1)%10)+1
Eg
Leaf Index = 4 -> subtract 1 = 3 -> %10 =3 -> add 1 = column 4
Leaf Index = 10 -> subtract 1 = 9 -> %10 = 9 -> add 1 = column 10
Leaf Index = 11 -> subtract 1 = 10 -> %10 = 0 -> add 1 = column 1
Add this into the table and apply/verify the table calculation settings are as above.

Now we know the Stem and the leaf row and column position, we can define the actual X and Y points for each leaf.
X Axis
FLOAT(IIF(MIN([Species])=’Iris-versicolor’, -1 * [Leaf Column Number], [Leaf Column Number]))
This is essentially just taking the Leaf Column Number and making it negative for the Iris-versicolor Species. We’ve wrapped it in a FLOAT to make the number decimal, as we need the axis to be able to handle decimal values later on.
For the Y Axis, we’re going to plot the leaves on rows at intervals of 0.2 related to the stem position
Y Axis
MIN([Stem]) + (0.2 * [Leaf Row Number])
Add these into the table and apply/verify the table calculation settings are as above.

Building the viz
Now we have the core data we need, we can start to build the viz
On a new sheet, add Species, Row ID, Stem and Leaf to Detail. Then add X Axis to Columns and Y Axis to Rows. Adjust the tableau calculation settings as before (remembering to apply the custom sort too!)

Change the mark type to circle. Add Species to Colour and adjust as required, adding a coloured border. Set the sheet to Entire View. Increase the Size a bit, then move Leaf from Detail to Text. Align middle centre and bold and allow labels to overlap. Reverse the Y Axis.

Fix the Y-Axis from 2.5 to 7 and set the tick marks to occur at intervals of 1.
Format Petal length (cm) to be a number with 1 dp, then add to Tooltip and adjust accordingly.
Set the background of the worksheet to pale blue. Remove column gridlines. Set the row gridlines to be a pale blue. Remove zero lines, axis rules & tick marks.

To plot the Stem value, double click into the Columns and manually type MIN(0.0) to create a second axis. Remove all the fields except Stem from the marks card of this axis. Change the mark type to shape and use a transparent shape. Move Stem onto Text and align middle centre and increase font size and make it bold. Clear all the text from the Tooltip associated to this mark.

Make the chart dual axis and synchronise the axis. Then add a Reference Band to the X-Axis which plots at -0.5 to 0.5, formatted with a blue line and a pale yellow fill.

Finally, hide all the axes (uncheck show header) and remove row & column dividers.
Add to a dashboard, using containers to organise the content. Use a horizontal container above the main viz to add text fields to label the parts of the chart. Ensure the chart specific title, the label headings and the chart itself are in a vertical container which can then have formatting applied (border/ curved edges etc). My dashboard item hierarchy is shown below

My published viz is here.
Happy vizzin’!
Donna






















































































































































