Updated: Feb 21
Tableau is an amazing tool that has created and fostered a community of data users passionate about data visualization. As a testament to that passion, we spend our time learning the ins and outs of data tools we use, figuring out what is possible, pushing its boundaries, and understanding why a tool is designed the way it is.
Not long after picking up Tableau, you begin to learn what visualization best practices are. Some best practices are chiefly important, like not overloading the user senses with an amalgamation of clashing colors and myriad of shapes / icons; others, like chart choice, are slightly peripheral and may be OK to break given the right circumstances.
One project I was working on recently had such a circumstance come up. Users wanted a % achievement KPI across 5 groups to be shown as a gauge chart. A gauge chart is essentially the top half of a donut chart, and a donut chart is a pie chart with a hole in the center (ad-lib food joke). Normally, best practices tell us to the use something like a bar chart; a visualization that makes it easy to compare across groups based on the relative height of the bars. Although a bar chart is a better choice from a best practice standpoint, there are a few reasons why I rationalized that a gauge chart could be ok:
The space within the gauge leaves plenty of room for a BIG KPI number
There was less focus on comparing across the groups
The groups were still sorted in descending order so relative ranking was still possible
Users found it more appealing / exciting to look at in this context.
Once I rationalized the decision to put a gauge, there was one hurdle left. At the time (April 16th 2020), there was no documented way of building out a gauge chart without densifying data. There was, however, a picture which I came across on the Flerlage twin’s blog post for Gauge Charts that made me think it should be possible to recreate without data densification.
The only hurdle is getting the ordering of the slices correct without the use of dimensions. Accomplishing this proved to be more simple than I had anticipated; all it took was understanding how Tableau would display the measures we add to our viz. Below are step-by-step instructions on how to create this chart; you can also download a packaged tableau workbook that has the final product and all calculations required at the bottom of the page.
Note: this can work for any numerical measure as long as you can express it as a part to whole relationship.
Creating the Framework for a Donut Chart:
Add any dimensions desired to the columns and rows shelf
Create a Dummy calculated field with the formula as MIN(0) and add it to the columns shelf
Fun tip: You can also double click into the columns shelf and type in MIN(0) without adding a dummy calculation to the fields in your data pane.
Duplicate the calculation (hold ctrl and click and drag the pill next to the original) so that it is on the columns shelf twice and make it into a dual-axis chart.
It may not be required but I still synchronize my dual axis always out of habit
Hide the headers and edit the line formatting so that we don’t have any rogue lines
Change the marks type for the left MIN(0) to be a pie chart and the right MIN(0) to be a circle.
Change the color of the circle to match the background of your dashboard and adjust the size.
When you finished, your chart should look similar to this:
Creating the Donut:
Make your calculated field which is a percentage (maximum of 100%) that you want to show.
If you name it "Donut Percentage" you can copy and paste the calculated fields I have written below.
Make 5 additional calculated fields; 4 of these (a - d) will use your percentage from step 1
First Quadrant Full:
IF [Donut Percentage] < .5 then [Donut Percentage] ELSEIF ISNULL([Donut Percentage]) Then 0 ELSE .5 END
First Quadrant Empty:
IF [Donut Percentage] < .5 then .5 - [Donut Percentage] ELSEIF ISNULL([Donut Percentage]) then .5 END
Second Quadrant Full:
IF [Donut Percentage] > .5 then IF [Donut Percentage] < 1 then [Donut Percentage] - .5 ELSE .5 END END
Second Quadrant Empty
IF [Donut Percentage] > .5 then IF [Donut Percentage] < 1 then1 - [Donut Percentage] ELSE 0 END else .5 END
Next is the trick to make it display appropriately with only using the measure values pill; Add all the calculated fields you created and re-order them so they pills are sorted like so:
Second Quadrant Full
Second Quadrant Empty:
First Quadrant Full
First Quadrant Empty
This works because tableau starts displaying the marks in the First Quadrant and works clockwise until all pills are displayed; by making the bottom equal to the sum of the top, we ensure that the Donut Bottom calc will always take up the bottom half of the donut.
Lastly, we need to change the color of the measure names as follows:
First Quadrant Full and Second Quadrant Full: Whatever color you want to represent the full portion
First Quadrant Empty and Second Quadrant Empty: A lighter color to represent the empty portion. I like light grey for this
Donut Bottom: Match the background color for your dashboard / viz.
Your viz should look similar to this when you are finished:
Now that we have our gauge, our goal is technically accomplished. However, as I alluded to in the intro, we can utilize the white-space in the center to offset the choice of the viz by adding more information. One simple way to do this is by:
Adding Some Polish:
Drag the [Donut Percentage] Calculated field onto the marks card for the secondary axis as a label.
Format as a percentage if needed, and edit the size and weight of the font so it stands out without extending beyond the inner circle.
Add new lines in the label text field after the percentage to move the label higher so that it sits in the top half of the gauge
Additional Options for Improvement:
To make a true gauge, we can add a pointer to show where the endpoint is.
If desired, we can take one of the short comings of these charts and use it to our advantage. Since it is harder for humans to discern differences between angles, we can hard code a small number that will be used to display the pointer without visibly distorting the view.
How to add a pointer:
Create two calculated fields:
First Quadrant Pointer
IF [Donut Percentage] < .5 then .0075 else IF ISNULL([Donut Percentage]) Then 0 ELSE 0 END
Second Quadrant Pointer
IF [Donut Percentage] >= .5 then .0075 else 0 END
c. Note: I chose .0075 (.75%) as the hardcoded number but you can choose anything. Just make sure it isn’t too big that it doesn’t distort the size and spacing of the viz too much.
Place each pointer calculation between the full and empty portion of each respective quadrant
Change the color of the Pointer marks to be something darker and contrast to the color used to fill the gauge.
Here is the finished product:
And that concludes the lesson. Thank you for reading – I hope you found it helpful. Feel free to comment below and/or share this post if you found it helpful.