How to Create a Calculated Field in Tableau

When I was building dashboards in Tableau for sales reporting, I faced an issue where the dataset didn’t always contain the exact fields I needed in the view. For example, sales amounts were there, but no profit margins were displayed. For these out-of-the-box values, we need to create calculated fields.

In Tableau, calculated fields allow us to create new columns or measures by using formulas, logic, and functions on an existing dataset.

In this Tableau tutorial, I will explain how to create calculated fields in Tableau and what their use is in creating chart views.

Create a Calculated Field in Tableau

In Tableau, there are two ways to create a calculated field, which are mentioned below.

  • In the Navigation bar, click Analysis tab -> Create Calculated Field.
Create a calculated Field in Tableau
  • Another option to create a calculated field is from the Data pane. In the Data pane, click on the dropdown near the search bar and select Create Calculated Field.
How to create Calculated field in Tableau

Using this approach, we can open the formula editor, in which we can define the calculated field.

Now, in the examples below, we will see different scenarios to create calculated fields in Tableau using the Superstore Datastore.

Example-1: Create a Calculated Field to Display Profit in Percentage

In this example, we will create a calculated field to show Profit Margin %, which shows the profit made per sale.

  1. To create a calculated field, right-click in the Data pane dropdown and select Create Calculated Field.
How to create Calculated field in Tableau
  1. Enter the calculated field label as Profit Margin, then enter the formula below and click OK.
SUM([Profit]) / SUM([Sales])
  1. To create the chart view, add the calculated field Profit Margin to the Columns and Sub-Category to the Rows.

As of now, the calculation is in number format. To change it to a percentage, click on the “Profit Margin” axis and select Format.

How to use calculated fields in Tableau
  1. In the Data Pane, select Default -> Numbers -> Percentage. Now, we can see the calculated field values in percentage.
Create Percentage Field in Tableau

This way, we can create a simple calculated field to show the profit percentage of sales.

Example-2: Create Calculated Field Using IF THEN Logic

In this example, we will create a calculated field using the IF THEN conditionals. In this calculated field, we will categorise orders as High Profit or Low Profit depending on whether the profit is above $1000.

  1. To create a calculated field, click on the Analysis tab and select Create Calculated Field.
Create a calculated Field in Tableau
  1. Label the calculated field as Profit Category and enter the formula below.
IF [Profit] > 100 THEN "High Profit"
ELSE "Low Profit"
END
  1. To create the chart view, add the Sub-Category to the Rows and Sales to the Columns.
  1. To categorise the data into “High Profit” and “Low Profit“, add the calculated field to the Colour card in the Marks section.
Create Calculated Field in Tableau

With this, we can view the data in two different colours, where the orange colour shows “Low Profit” and the blue colour shows “High Profit“.

This way, we can create a calculated field in Tableau using the IF-THEN conditionals.

Example-3: Create a Filter using Calculated Field

In this example, we will create a filter using the calculated field. Here, we will define the conditions in the formula that will return values based on conditions.

For example, we want to filter the customers whose total sales exceed $10,000. Now, follow the steps to filter records based on the conditions.

  1. Click on the Analysis tab and select Create Calculated field.
  1. First, we will create a calculation to get the customer sales using the formula below.
{ FIXED [Customer Name] : SUM([Sales]) }
  1. Now, create another calculated field, Top Customers, and enter the formula below to get the sales of top customers.
IIF([Customer Total Sales] > 10000, "Top", "Others")
  1. Drag the calculated field Top Customers to the Filter section and select Top, then OK.
Create custom calculated field in Tableau
  1. To create the chart view, drag the Calculated field Top Customer Sales to Columns, Customer Names to Rows and Sales to Text card.
Create filter using Calculated field in tableau

Now, we can see the Sales for the top customer, whose sales exceed $100,000.

Other than this, we can also use the calculation fields in Tableau conditional formatting, Level of detail operations and creating groups or sets.

Conclusion

In this Tableau tutorial, we have learned how to create calculated fields in Tableau. In the above examples, we created calculations to display profit margins, categorising sales with IF-THEN logic, or filtering top customers using LOD calculations.

By following the above examples, you can create calculated fields tailored to different requirements, highlight trends, or group data into categories.

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.