How to perform Numeric, String and Date Calculations in Tableau

Last updated on Oct 25 2021
Anand Vishwanathan

Table of Contents

How to perform Numeric, String and Date Calculations in Tableau

Tableau Numeric Calculations

In Tableau, numeric calculations are done using a wide range of inbuilt functions available in the formula editor.
Let’s see how to apply calculations to the fields. The calculations are simple as subtracting the values of two fields or using an aggregate function to a single field.
Here are the steps to create a calculation field and use numeric functions in it.

How to Create a Calculated Field

• After connecting to a data source such as Sample-Superstore.
• Go to Analysis menu.
• And click on Create Calculated Field as shown in the below image.

Page 1 Image 1 31
Create Calculated

Calculation Editor in Tableau

The above process opens a calculation editor which lists all the functions available in Tableau.

Page 2 Image 2 29
calculation editor

You can change the dropdown value and only see the related functions to numbers.

Page 2 Image 3 15
dropdown

Create a Formula

o visualize the difference between Profit and Discount for different shipping mode of the products, create a formula that subtracts the Discount from the Profit, as shown in the below image, and the name of this field is profit_n_discount.

Page 2 Image 4 2
Create a Formula

Using the Calculated Field

The above-calculated field can be used in the view by dragging it to the Rows shelf as shown in the below screenshot.
It produces a bar chart that shows the difference between profit and discount for different shipping modes.

Page 3 Image 5 10
Using Calculated Field

Applying the Aggregate Calculations

You also can create a calculated field using an aggregate function.
• First, create AVG (sales) values for different ship mode.
• Then, Write the formula in the calculation editor as shown in the below screenshot.

Page 3 Image 6 2
Write formula

• Click OK and dragging the Avg_Sales field to the Rows shelf, then you get the following view.

Page 4 Image 7 10
Avg_Sales

Tableau String Calculations

Tableau has many inbuilt string functions used for string manipulation such as concatenating, comparing, and replacing few characters from a string, etc.
Here are some steps to create a calculation field and use string function in it:

How to Create Calculated Field

• After connecting to a data source such as Sample superstore.
• Then, go to the Analysis menu.
• And click ‘Create Calculated Field’ as shown in the below image.

Page 5 Image 8 7
Create Calculated Field

Calculation Editor in Tableau

The above process opens a calculation editor that contain all the functions available in Tableau.

Page 5 Image 9 4
Calculation Editor

You can change the dropdown value and only see the related functions to strings.

Page 6 Image 10 5
dropdown

Create a Formula

• If you want to find out the Sales in the Cities, that contain the letter “A”, create the formula as shown in the below image.

Page 6 Image 11 3
Create

How to Use the Calculated Field

To see the created field into a graphical representation, you can drag City field into the Rows shelf and drag the Sales field into the Columns shelf.
The below image shows the Sales values for Cities:

Page 7 Image 12 4
Sales values

Tableau Date Calculations

Tableau can provide a large number of inbuilt functions such as dates. Dates are one of the critical fields which are extensively used in most of the data analysis.
You can manipulate the simple date such as adding or subtracting days from a date. Also, you can create complex expressions that include dates.
Here are the steps to create a calculation field and use date functions in it.

How to create a calculated field

• After connecting to a data source such as sample superstore.
• Then go to the Analysis menu.
• And click on the ‘Create Calculated Field’ as shown in the below image.

Page 8 Image 13
Analysis

Calculation Editor in Tableau

The above process opens a calculation editor that lists all the functions available in Tableau.

Page 8 Image 14 3
opens

You can change the dropdown value and only see the related functions to date, shown in the below image:

Page 9 Image 15 1
functions

Create a Formula

If you want to find out the Sales volume along with the difference in the date of sales in months from 15/06/2015 to 15/02/2015, create the formula as shown in the below image.

Page 9 Image 16 3
a Formula

Using the Calculated Field

To see the created field in graphical representation, you can drag Month and date_diff field into the Rows shelf and drag the Sales field to the Columns shelf. Also, drag the ship Date with months.
The below screenshot shows the Sales volume along with the difference in the date of sales:

Page 10 Image 17 1
Sales volume

So, this brings us to the end of blog. This Tecklearn ‘How to perform Numeric, String and Date Calculations in Tableau’ blog helps you with commonly asked questions if you are looking out for a job in Tableau Desktop. If you wish to learn Tableau Desktop and build a career in Business Intelligence domain, then check out our interactive, Tableau Desktop Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

Tableau Desktop

Tableau Desktop Training

About the Course

Tecklearn’s Tableau Desktop Training teach you how to transform raw data into interactive and shareable dashboards using Tableau. Our Tableau Course covers the necessary analytical skills to Advanced data visualizations by incorporating real-world use-case scenarios, labs, and exercises. Some of the topics included are Data Blending, Data Mapping, Graphs, creation of charts, and LOD expression by using different versions of Tableau, such as Tableau Desktop, Tableau Reader, and Tableau Public.

Why Should you take Tableau Desktop Training?

• The average salary of a Tableau Professional ranges between $108,697 to $158,000 per annum -Indeed.com.
• Tableau has been positioned as a Leader in the Gartner Magic Quadrant for Analytics and Business Intelligence Platforms – Gartner.com.
• Fidelity Investments, Capgemini, EY, Deloitte, EY, JP Morgan, Verizon, Facebook, Dell, General Motors, KPMG, Bank of America and 40,000 other MNCs worldwide across industries use Tableau.

What you will Learn in this Course?

Understanding Tableau

• Why Tableau
• Tableau Product Platforms
• Tableau Architecture
• Tableau Interface

Data Connection with Tableau Desktop

• Features of Tableau Desktop
• Connect to data from File and Database
• Types of Connections
• Data Blending
• Joins and Unions
• Tableau Desktop User Interface
• Basic project: Create a workbook and publish it on Tableau Online

Basic Visual Analytics

• Visual Analytics
• Basic Charts: Bar Chart, Line Chart, and Pie Chart
• Hierarchies
• Data Granularity
• Highlighting
• Sorting
• Filtering
• Grouping
• Sets

Advanced Visual Analytics

• Parameters
• Tool tips
• Trend lines
• Reference lines
• Forecasting
• Clustering

Calculations in Tableau

• Calculated Fields
• Numeric, String, Data, Logical, Addressing and Partitioning
• Table Calculations

Level of Detail (LOD’s) Calculations

Advanced Charts in Tableau

• Box and Whisker’s Plot
• Bullet Chart
• Bar in Bar Chart
• Gantt Chart
• Waterfall Chart
• Pareto Chart
• Control Chart
• Funnel Chart
• Bump Chart

Parameters

• What If Scenarios
• Parameter in CF (KPI control)
• Parameter in Filter (Top N)
• Parameter in reference line

Dashboards and Stories

• Introduction to Dashboards
• The Dashboard Interface
• Dashboard Objects
• Building a Dashboard
• Dashboard Layouts and Formatting
• Interactive Dashboards with actions
• Designing Dashboards for devices
• Story Points

Data Security in Tableau

Optimizations tips and tricks

Interacting with Tableau Server

Working with Tableau JavaScript API

Got a question for us? Please mention it in the comments section and we will get back to you.

0 responses on "How to perform Numeric, String and Date Calculations in Tableau"

Leave a Message

Your email address will not be published. Required fields are marked *