Calculating percentages and proportions
This quick tutorial shows you how you can calculate percentages and proportions of totals in Tableau, for example how to calculate profit margins
How to calculate percentages and proportions in Tableau
Quite often in Tableau you'll have the need to work out the proportion of one measure to another, or to calculate a percentage. A good example of this is calculating what the proportion of profit it as a percentage of sales (usually referred to as profit margin).
While this may already be pre-calculated in your data one of the main advantages of calculating this within Tableau is that you can then see the proportion at the granularity that you want.
As an example, if you had the profit margin for each order within your data you could use this to compare the profit margin across orders and to also look at an average of the profit margin at higher levels but you wouldn't be able to use this to work out the actual profit margin at various levels such as at a product, region or global level.
With Tableau, calculations are done on the fly depending on the granularity of the data in your view which makes this a lot more flexible and creating these calculations are very simple in Tableau.
Step by step instructions on calculating percentages and proportions in Tableau
In Tableau go to Analysis in the top menu and select Calculated Fields and Create New Calculated Field (you can also use the shortcut keys ALT, a, c to quickly do this).
In this example we're going to calculate the proportion of profit based on the sales value of each order, to do this enter the following into the calculation window SUM(Profit)/SUM(Sales).
The reason we use SUM is to tell Tableau that we we first want to sum up the profit at the level in the view and divide this by the sum of sales at the same level. If we omitted this Tableau would calculate the profit margin at the lowest level in the data and then sum all of these results up in the view which would be incorrect.
Name the calculation as Profit Margin
Click OK.
Drag and drop the new Profit Margin field onto your view and this will show you the total profit margin for your data.
Drag and drop one of your dimensions onto the rows and you'll then see how the profit margin is dynamically calculated at this level.
You'll also want to format your field so that you don't need to do this each time it's added.
The video below runs through how to do this: