How to Create Calculated Field in Tableau

# How to Create Calculated Field in Tableau

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.

## 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
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
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
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

#### Create Calculated Field

• Select Analysis -> Select Create Calculated Field
• Enter the name Profit-Sale Ratio
• Enter the Formula

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.

#### Add Calculated Field in the View

• Drag and Drop Profit-Sale Ratio on the Mark Card

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
Tableau supports seven different data types and it tableau automatically assigns a data type and role to each column.
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
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.

### 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.