Blog Blog Posts Business Management Process Analysis

An Introduction to Tableau Calculated Fields and Its Function

Tableau Calculated fields can be used to create new dimensions such as segments, or new measures such as ratios or sums. They can be used with any data type, various functions and aggregations, logical operators, making the calculated results virtually limitless. In this blog, we will be introducing Tableau Calculation fields by walking through the following topics.

Check out this video to get started with concepts of Tableau calculations.

Why use Tableau Calculation Fields?

Before connecting data sources to Tableau, it is always suggested to collect as much data as possible. Shouldn’t this data include all of the required fields for the analysis then?

There are many reasons for using calculation fields functionality in Tableau. The below are a few of them:

  1. To filter out unwanted results for better analysis
  2. To segment data in new ways
  3. To calculate ratios across different variables in Tableau, saving database processing and storage resources
  4. To convert the data type of a field, such as converting string to date
  5. To aggregate data

Types Of Calculations

Calculated Fields in Tableau are created using calculations. The calculations in tableau which can be used to create calculation fields are categorized into three classes which are mentioned below.

  1. Basic Calculations- These calculations allow us to transform values at a data source level of detail or at a visualization level of detail(aggregate calculation).
  2. Level Of Detail Expressions- The second way of creating a calculating field is by using LOD expressions.  LOD calculations allow you to compute values at the data source level and visualization level, as well as give us even more control over the level of granularity we want to compute.
  3. Table Calculations – These calculations allow us to transform values at the visualization level of detail only.

The choice of calculation depends on the type and requirements of your analysis.

How To Add Calculated Field in Tableau

In this example, we are using the Sample-Superstore data source that comes with Tableau Desktop to create a Calculated Field.

Calculated Field
Field in Tableau

The new Calculation field is added to Measures in the Data pane as shown below.

Tableau Conditional Calculated Field

Sometimes, during data analysis, we only require certain values of a particular field. This can be implemented by creating a Tableau conditional calculated field. Using these fields you can create conditional data labels on a custom field that includes only values of interest.

Get started with the Tableau Certification Training course and become a certified professional.

Tableau Calculated Field If-Then Statements

If statements are a fundamental part of Tableau or any other analytics platforms and programming languages. Understanding what Tableau calculated  IF-THEN statements do and how they work is critical when building calculated fields.

The IF keyword tells Tableau that we are about to perform an IF statement. THEN indicates that we are about to specify some return value. In between IF and THEN is what is referred to as a conditional expression. When these expressions are used in the calculation field it becomes a Conditional Calculated Field.

How to Create a Conditional Calculated Field

 The following are the steps to create a conditional calculated field.

Become a Business Intelligence Architect

Tableau Calculated Field Order Of Operations

Now that we know about IF statements, let’s learn a bit more about some complex logical issues we may encounter. For example, consider the following expression

IF[Category]= “Office Supplies” OR [Category]= “Technology” AND [Order Date] >= #01/02/2020# THEN

When we have an expression consisting of multiple logical expressions, the order of precedence plays an important role. The order of operations is just like the one used in equations in mathematics. The precedence order of the operations is as follows:

  1. Parentheses
  2. NOT
  3. AND
  4. OR

Hence, the first thing to be computed in a logical statement is the parentheses, which group comparisons together. The next one is NOT, followed by AND then OR. If we apply for this order in the above example, the two comparisons separated by AND will be evaluated first.

[Category]= “Technology” AND [Order Date] >= #01/02/2020#

This expression result gives us anything with a category of “Technology” and an order date on or after February 1, 2020.

The OR will then act as if the above statement is a single expression. So, in layman terms, the original statement will give us anything where the category is “Office supplies” OR the category is “Technology” and the order date is on or after February 1, 2020.

Since it can be difficult to think through the order of operations while writing an IF statement, it is recommended to always use parentheses to group your conditions.

Career Transition

How To Do Group By in Tableau Calculated Field

In Tableau, we can create a group to combine related members in a field. For instance, if we are working with a view that shows average sales by sub-categories, we might want to group certain sub-categories together. Groups are useful for both correcting data errors and are also helpful in answering “what if” type questions.

Now, let’s create a group to understand the concept in more detail.

Tableau calculated field sum by groups

This calculation field can be used for instances like to find the sum of sales for each category. This example can be implemented as follows.

  1. Click on Analysis >> Create Calculated Field
  2. Name the field and implement the calculation in the field
  3. Click OK

Tableau Create Bins From Calculated Field

In Tableau, we can create bins from a calculated field. Any discrete field in Tableau can be considered as a set of bins. For instance, if we create a view with profit as a row and state as a column, we can consider the state field as a set of bins, that is each profit value is sorted into a bin corresponding to the state from which the value was recorded.

Let’s study how to create bins from a measure calculated field in Tableau.

Click OK and you will see a new binned field will appear in the Dimensions area of the Data pane.

When we add a binned dimension to the view, each bin acts as an equal-sized container that totals data for a specific range of values. These binned dimensions are further used to create histograms.

Tableau Sort By Calculated Field

In Tableau, it is possible to create custom and dynamic sorts by using a mixture of parameters and calculated fields. To sort by a calculated field there are 2 options:

  1. Use the field in the sort – field section of the field sort menu
  2. Place the sorting calculated field as a discrete pill to the left of the fields to sort

In this example, we are using Superstore Sales sample data that Tableau provides.

Date Difference in Tableau Calculated Field

One of the interesting functions in Tableau is the DATEDIFF function. When this function is used within a calculated field, you can quickly start calculating date differences in Tableau using two date fields. Let’s see the following example along with implementation to understand in a better way.

So, in this example, we are calculating the difference between the order date and shipping date, as its analysis can help us in enhancing effective delivery time.

Hence, we can use the Date difference feature for very useful data analytics and visualization.

Exclude in Tableau Calculated Field

Exclude level of detail expressions prevent the calculation from using one or more of the dimensions that are present in the view. These expressions are especially useful for ‘percent of total’ or ‘difference from overall average’ situations.

For instance, if we want to calculate the sum of sales by excluding a particular region, we can follow the given steps and create a new calculated field “Region Excluded”.

  1. Click on Analysis >> Create Calculated Field
  2. Name it as “Region Excluded”
  3. Implement the following expression in the dialog box

This field, thus, can be further used to sort or arrange other dimensions during the visualization and analysis of the data.

In this way, the Calculated fields in Tableau are of great help in implementing efficient and accurate data analytics. We hope this article has shed some light on various concepts of Calculated Fields in more detail.

Check out our Business Intelligence Community for more information about Tableau

The post An Introduction to Tableau Calculated Fields and Its Function appeared first on Intellipaat Blog.

Blog: Intellipaat - Blog

Leave a Comment

Get the BPI Web Feed

Using the HTML code below, you can display this Business Process Incubator page content with the current filter and sorting inside your web site for FREE.

Copy/Paste this code in your website html code:

<iframe src="https://www.businessprocessincubator.com/content/an-introduction-to-tableau-calculated-fields-and-its-function/?feed=html" frameborder="0" scrolling="auto" width="100%" height="700">

Customizing your BPI Web Feed

You can click on the Get the BPI Web Feed link on any of our page to create the best possible feed for your site. Here are a few tips to customize your BPI Web Feed.

Customizing the Content Filter
On any page, you can add filter criteria using the MORE FILTERS interface:

Customizing the Content Filter

Customizing the Content Sorting
Clicking on the sorting options will also change the way your BPI Web Feed will be ordered on your site:

Get the BPI Web Feed

Some integration examples

BPMN.org

XPDL.org

×