How to Create Calculated Field in Tableau

How to Create Calculated Field in Tableau

3 mins read1.3K Views Comment
Vikram
Vikram Singh
Assistant Manager - Content
Updated on Jun 14, 2022 10:06 IST

In this article, we will discuss how to create and use the calculation in Tableau, and we will also discuss why to use calculated fields in Tableau.

2022_06_feature-images_calculated-fields.jpg

Table of Content

What are Calculated Fields

In the tableau, columns in the dataset (or database) are known as fields, where Calculated Field is a field (or columns) that uses the fields of the given dataset and applies additional logic- it allows the creation of a new field from the given dataset.

Calculated field either:

  • Do some calculations on the given fields of the dataset to create a value that is not present in the dataset
  • Select values from the dataset based on the user-defined criteria

Note: 

  1. The new calculated field is saved to your data source in Tableau and can be used the same way as the other fields in the data source.
  2. The original fields in the dataset remain unchanged.

Must Check: What is Tableau?

Must Check: Tableau Online Courses & Certifications

When to use Calculated Fields

Calculated fields are a flexible and efficient way to do analysis.

Some common scenarios where calculated fields are used in Tableau:

  • The data you need for analysis is missing in the given dataset (or Data Source)
  • Want to transform values in the visualisation
  • Want to categorise data quickly

Examples of Calculated Fields in Tableau:

  • Segment Data
  • Aggregate data
  • Convert Data Type
  • Filter Data
  • Calculate Ratios
How to Create a Word Cloud in Tableau
How to Create a Word Cloud in Tableau
In this article, we will briefly discuss about word cloud in tableau and how to create word cloud with an example.
How to Create a Forecast in Tableau
How to Create a Forecast in Tableau
In this article, we will discuss what is forecasting, how does forecasting works in tableau, data requirement and constraints and finally how to create forecasting in tableau.
How to Create Hierarchies in Tableau
How to Create Hierarchies in Tableau
In this article, we will discuss hierarchies in tableau, how to create and remove hierarchies in tableau with examples.

Types of Calculation

There are three main types of calculation that we can use to create a Calculated Fields in the Tableau:

  • Basic Expression
    • Allows to transform values or members at the data source level of details (a row-level calculation) or at the visualization level of details ( an aggregation calculation)
  • Level of Detail (LOD) Expressions
  • Table Calculations

Create a Calculated Field

We will see how to create a calculated field with the help of an example.

Here, we will use the Sample Super Store Data.

Problem Statement: Calculate Profit Sale Ratio of products subcategories within different states.

Steps to Create Calculated Fields:

Build the View

  • Connect the Sample Super Store Data
  • Drag and Drop State into the column shelf
  • Drag and Drop Category and Sub-Category into the row shelf
2022_06_calculated-field_build-the-view.jpg

Create Calculated Field

  • Select Analysis -> Select Create Calculated Field
    • Enter the name Profit-Sale Ratio
    • Enter the Formula
2022_06_calculated-field_formula_profit_sale_ratio.jpg

Note: The above formula:

  1. Checks Sales is not equal to zero
  2. If True, return Profit ratio ([Profit]/[Sales])
  3. If False returns 0
  • Click OK
  • New Calculated Field Profit-Sale Ratio is added in the Data Pane

Note: All the calculated fields have an equal sign (=) next to them in the Data Pane.

2022_06_calculated-field_data_pane.jpg

Add Calculated Field in the View

  • Drag and Drop Profit-Sale Ratio on the Mark Card
2022_06_calculated-field_Add-Calculated-Field-in-the-View.jpg

Note: By Default, Profit-Sale Ratio is aggregated as a sum, we can change it to AVG, MEDIAN, MODE, Maximum, Minimum etc by

Right-Click on SUM(Profit-Sale Ratio) in the Mark Card -> Select Measure (SUM).

Dimension and Measure in Tableau
Dimension and Measure in Tableau
Tableau supports seven different data types and it tableau automatically assigns a data type and role to each column.
In this article, we will discuss one of the important concepts...read more
How to Create Group in Tableau
How to Create Group in Tableau
In this article, we will briefly discuss about groups in tableau, how to create groups and finally what are the differences between tableau groups and tableau sets.
Data Aggregation in Tableau
Data Aggregation in Tableau
In this article, we discussed different aggregation functions in tableau, how to change the aggregation of a measure in a view and how to disaggregate the data.

Additional Resource

Edit a Calculated Field

  • Right Click on Profit-Sale Ratio in the Data Pane
  • Select Edit
    • Calculation Editor Dialog Box will appear with the previous formula, you can update
      • Name of Calculated Field
      • Formula
  • Click OK

Tips for Working with Calculated Fields

  • Drag and Drop fields into the Calculation Editor
  • Drag and Drop formulas from the Calculation Editor back to Data Pane
  • Use functions reference in the calculation editor
    • To open the functions reference, click the triangle icon on the right side of the Calculation Editor Box.

Conclusion

In this article, we have discussed how to create and use the calculation in Tableau, and we will also discuss why to use calculated fields in Tableau.

Top Trending Articles:

Introduction To Tableau | Products Of Tableau | Data Types In Tableau | Change Data Type In Tableau | File Type In Tableau | Data Aggregation | Connecting Data In Tableau | Dimension And Measure | Tableau Show Me | Joins In Tableau | Union In Tableau | Operators In Tableau | Number Functions In Tableau | String Functions In Tableau | Filter In Tableau | Context Filter In Tableau | Filters In Tableau | Types Of Charts In Tableau | Bar And Line Chart In Tableau | Pareto Chart In Tableau | Gantt Chart In Tableau | Box And Whisker Chart In Tableau | Waterfall Chart In Tableau | Donut Chart In Tableau | Funnel Chart In Tableau | Dual Axis Chart In Tableau | Sort Data In Tableau | Tableau Sets | Groups In Tableau | Tableau Hierarchy | Tableau Forecasting | Highlighting In Tableau | Word Cloud In Tableau | Cohort Analysis In Tableau

About the Author
author-image
Vikram Singh
Assistant Manager - Content

Vikram has a Postgraduate degree in Applied Mathematics, with a keen interest in Data Science and Machine Learning. He has experience of 2+ years in content creation in Mathematics, Statistics, Data Science, and Mac... Read Full Bio