How to Calculate Percentage of Total in Tableau

Recently, I created a stacked bar chart to show the sales of product categories for each region. In this chart, when I tried to show the percentage, it was showing the percentage of the running total instead of the percentage of the total.

Then, using the quick table calculation, I was able to display the percentage of total on the Tableau stacked bar charts. Along with this, I also found other ways through which we can calculate the percentage of total, which use WINDOWS_SUM, INCLUDE LOD and EXCLUDE LOD.

In this tutorial, I will explain how to calculate the percentage of total in Tableau with the help of four different methods.

Percentage of Total in Tableau

In Tableau, the percentage of total calculates the proportion each part contributes to the whole by dividing a measure’s value by the sum of that measure for all parts. We can apply this quickly using Tableau’s Quick Table Calculation feature, or create custom calculations with Level of Detail (LOD) expressions like FIXED or EXCLUDE and also using the WINDOWS_SUM.

Calculate Percentage of Total in Tableau

In the examples below, we will calculate the Percentage of the Total in Tableau using the methods below.

  • Calculate the percentage of the total using Quick Table
  • Calculate the percentage of the total using EXCLUDE LOD
  • Calculate the percentage of the total using FIXED LOD
  • Calculate the percentage of the total using WINDOWS_SUM

Calculate the Percentage of Total Using Quick Table Calculation

In this example, we will calculate the percentage of the total using the quick table calculation.

In this data visualisation, we will create a stacked bar chart using the Tableau Superstore dataset.

  1. To create the stacked bar chart, add ‘Region’ to ‘Columns‘ and ‘Sales’ to Rows.
  1. Add the Category dimension to the Colour card in the Marks section. This will stack the Categories for each region in a single bar.
Calculate percentage of total in Tableau
  1. Add the Sales to the Text card in the Marks section. After this, click on the Sales and select Quick Table Calculation -> Percent of Total.
Tableau Percentage of Total

Now, we can see the percentage of the total for the share of sales of each category in a specific region.

Tableau Percentage of Total in Bar chart
  1. In this, we can also show the overall total at the top of the bar instead of showing it for each stacked measure. To do this, duplicate the Sales in the Rows and create a Dual Axis chart.
Stacked bar chart percentage of total in tableau
  1. Remove the Sales from the Label of Sales(1) axis and Category from the Colour of Sales(2) axis.
  1. Set the Marks type for the first axis as a Bar chart and for the second axis as a Gantt chart.
Use quick table calculation in Tableau
  1. If the percentage values are not aligned properly at the top of the bars, then right-click on the axis and select ‘Synchronise Axis‘.
Quick table calculation for percent of total in tableau

Now, we can get the percentage of the total for all stacked dimensions at the top of the bars.

Percent of total in Tableau stacked chart

This way, we can calculate the percentage of the total in Tableau by using the quick table calculation.

Calculate the Percentage of Total Using EXCLUDE LOD

In this method, we will calculate the percentage of the total using the EXCLUDE LOD in Tableau. This will display each category’s sales as a percentage of the overall total, ignoring Category.

Now follow the steps below to calculate the percentage of total using the EXCLUDE LOD in Tableau.

  1. Create a calculated field and label it as Sales % of Total (EXCLUDE), then enter the formula below.
SUM([Sales]) / SUM({ EXCLUDE [Category] : SUM([Sales]) })

In this formula, { EXCLUDE [Category]: SUM([Sales])} gives the total sales excluding the category. Then divide the category’s sales by this total.

  1. To create the view, Category to Columns and Sales to Rows.
  1. Now add the calculated field to the Text card in the Marks section. To show the values in percentage, click on the calculated field in the label and select Format.
Tableau Calculated field to show percent of total
  1. In the Format, go to the Default section and select Numbers -> Percentage. Here, we can also select the Decimal places for the percentage values.
Show percent of total in Tableau

This way, we can calculate the percentage of the total using the EXCLUDE LOD in a calculated field.

Calculate the Percentage of Total Using FIXED LOD

In this example, we will calculate the percentage of the total using the FIXED LOD in a calculated field.

For this method, we will show each category’s sales as a percentage of the grand total, even when other dimensions like Sub-Category are there in the view.

  1. First, create a calculated field, Sales % of Total (FIXED) and enter the formula below.
SUM([Sales]) / SUM({ FIXED : SUM([Sales])})

In the formula above, { FIXED: SUM([Sales]) } locks the calculation to the entire dataset (fixed across all dimensions) and returns total sales. Then it divides category sales by this overall total to get the percentage of the total.

  1. To create a view, add a Category and optionally a Sub-Category to Rows.
  1. Add the calculated field to the Text or Tooltip card in the Marks section.
  1. Change the calculated field format to Percentage, and it will display the percentage of the total for each sub-category.
Tableau Percentage of Total using Fixed lod

This way, we can calculate the percentage of the total for the dimensions using the FIXED LOD in Tableau.

Calculate Percentage of Total Using WINDOWS_SUM

In this method, we will calculate the percentage of the total using the WINDOWS_SUM in Tableau.

The WINDOW_SUM is a table calculation function that is used to sum aggregated values within a defined “window” of data. This method is useful when the table view is already aggregated.

  1. Create a calculated field, Sales % of Total (WINDOWS_SUM), and enter the following formula.
SUM([Sales]) / WINDOW_SUM(SUM([Sales]))

In the above formula, WINDOW_SUM(SUM([Sales])) calculates the sum of all rows in the current table window.

  1. To create the view, drag the Sub-Category to the Rows and the calculated field to the Text card in the Marks section.
Create a calculated field to show percent of total
  1. Click on the dropdown of the calculated field in the Marks section and select Compute Using -> Table (down).
Tableau Percentage of Total calculation
  1. Change the calculated format to a percentage. For this, click on the calculated field and select Format. In the format, select Number -> Percentage.
Show percent of total in Tableau using WINDOWS_SUM

With this, we can see the percentage of the total for the Sales percentage share of Sub-Categories. This way, we can calculate the percentage of the total using the WINDOWS_SUM function.

Conclusion

In this Tableau tutorial, we have learned different ways to calculate the percentage of total in Tableau using Quick Table Calculation, EXCLUDE LOD, FIXED LOD, and WINDOW_SUM.

In the above methods, the Quick Table Calculation is the simplest way, while EXCLUDE and FIXED LODs give more control for consistent totals regardless of the view. The WINDOW_SUM method is a table calculation useful for aggregated views.

By choosing any of the above methods, we can calculate and display the percentage of the total in Tableau data visualisation.

You may also like to read:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.