This post describes how to build a doughnut-chart with Tableau based on a calculated percentage (single measure). The first part of this post is showing you how to do this without conditional coloring, while the second part shows you a slightly different approach to enable some conditional coloring in the doughnut.

01. DataSetFor this example we’ll be using a simple data set having 3 products, each with its own sales and costs. With these figures we can easily calculate the products profit margin.

Now create your calculated field that looks like this:

ProfitMargin: (SUM([Sales])-SUM([Cost]))/SUM([Cost])

Usually when creating pie-charts or doughnut-charts you would use a category field but in this case we can’t use that because we don’t have any categories for our data. Therefore we need to create a second calculated field to fill in the rest of our doughnut chart

RestProfitMargin: 1-[ProfitMargin]

Creating a doughnut chart with no specified color-indicator.

In the standard doughnut you drag your “Measure Values” into your Text Mark and your “Measure Names” into your Detail Mark. Now remove all measures except for our ProfitMargin and RestProfitMargin. It should look like this now:

04. MeasureValues

Now select the Mark Type Pie.

05. Mark Type Pie

And now you have your Pie Chart:

06. Pie Chart

For turning this into a doughnut chart we can easily add a measure into our row-section. I’m using the “MIN(Number of Records)” or you could you use a constant value for this. Just make sure both row measures have the same value.

07. RowMembers

As you can see, Tableau has made this into a Multiple Mark Type visualization. For the second Mark remove the objects of the Color Marks, Angle Marks and Label Marks. Modify the Size Mark and make it slightly smaller. (Maybe you can set default color to white)

08. Cleanup Second Pie

Now you can right-click the second row measure and make them Dual Axis. Et voila, you’ve got your doughnut chart. Just clean up labels, hide headers and format your measures and you’re good to go.09. DoughnutNoColor

How to setup conditional coloring in single measure doughnut chart.

To do so we need to create some (new/additional) calculated fields:

PositiveProfitMargin:
IF [ProfitMargin] >= 0 THEN [ProfitMargin] END

PostitiveRestProfitMargin:
IF [ProfitMargin] >= 0 THEN 1-[ProfitMargin] END

NegativeProfitMargin:
IF [ProfitMargin] < 0 THEN [ProfitMargin] END

NegativeRestProfitMargin:
IF [ProfitMargin] < 0 THEN 1-[ProfitMargin]

The calculations will return nothing or NULL if criteria is not true.

Now do the same actions as a described in the first part using these 4 measures.

10. MultiMeasureValues

Because of the multiple measures we can now specify our color on the different measure. Edit colors of the [Measure Names]

11. MeasureNamesColor

If you add the ProductName on the columns you would get this result:

12. Productdoughnut

We can show the actual ProfitMargin in the inner circle of the doughnut chart and use the same conditional coloring. Simply add PositiveProfitMargin and NegativeProfitMargin to the Label Mark. Now edit the labels and add color to each of the labels.

13. LabelFormatting

The result:

14. TheResult

Author
Bjorn Cornelis

Bjorn Cornelis

I help you get insights from your data. Easier. Faster.

Read more articles of this author
Let's discuss your data challenges

Join our community of data enthusiasts

Get industry insights, expert tips and Biztory news sent straight to your inbox with our monthly newsletter.