Perform Calculation and Operators and Functions in Tableau

Last updated on Oct 25 2021
Anand Vishwanathan

Table of Contents

Perform Calculation and Operators and Functions in Tableau

There are four necessary components to the calculation in Tableau:
1. Function: Function statements are used to transform the values or members in a field.
For Example: The format of all functions in Tableau such as SUM (expression).
2. Fields: Field is dimensions and measures from your data source.
For Example: A field in a calculation is often surrounded by brackets [ ] such as [Sales].
3. Operators: Operator is a symbol that denotes an operation between the operands.
For Example: The types of operators you can use in Tableau calculations, as well as the order they are performed in a formula such as +, -, *, /, %, ==, =, >, <, >=, <=, ! =, <>, ^, AND, OR, NOT, ( )
4. Literal Expression: Literals expression are representing the constant values “as is” such as “profitable” and “unprofitable”.
For Example: See the below calculation
1. IF [Profit per Day] > 5000THEN”Highly Profitable”
2. ELSEIF [Profit per Day] <= 0THEN”Unprofitable”
3. ELSE “Profitable”
4. END

The component of the above calculation can be further divided into the following:
I. Functions: IF, THEN, ELSEIF, ELSE, and END.
II. Field: Profit per Day.
III. Operators: > and <=.
IV. Literal Expression
o String Literals: “Highly Profitable”, “Unprofitable”, and                                      “Profitable”.
o Numeric Literals: 5000, and 0.

Note: Not all calculation needs to contain all the four components.

Here is some important point for literal expression syntax:

• Numeric literals are written as numbers.
Example: 27 or 1.3567
• String literals are written with quotation marks.
Example: “profitable.”
• Date literals are written with the # symbol.
Example: # June 8, 2018 #
• Boolean literals are written as either true or false.
Example: “True” or “False”
• Null literals are written as null.
Example: “NULL”

Two more calculations contain by Tableau

1. Parameters: Parameter is a placeholder variable that can be inserted into calculations to replace the constant values.
A parameter in a calculation is surrounded by brackets [ ].
For Example: [Profit Bin Size]
2. Comments: Comment is defined as the notes about a calculation or its parts, but comments not included in the computation of the calculation.
To enter a comment in a calculation, use two forward slashes //.
For Example
1. SUM ([Sales]) / SUM ([Profit]) // Nick’s calculation
2. // to be used for profit ratio
3. // Do not edit

Tableau Operators

An operator is a symbol for performing specific mathematical and logical operations through the compiler.
Tableau has several numbers of operators which are used to create calculated fields and formulas.
Here are the types of operators with their order of precedence of operation:

Types of operators

1. General operators
2. Arithmetic operators
3. Relational operators
4. Logical operators

1. General Operators

Here are some general operators supported by Tableau. These operators act on the character, numeric, and date data type.
• Addition (+): By the help of the addition operator, we can add the two numbers, concatenate two strings and also add days to dates.
Example: 10+15=25
Sales+ profit
‘XYZ’+ ‘PQR’= XYZPQR
# June 8, 2018 # + 7= # June 15, 2018 #
• Subtraction (-): By the help of the subtraction operators, we can subtract two numbers and subtract days from dates.
Example: – (10+15) = -25
# June 8, 2018 # – 7= # June 1, 2018 #

2. Arithmetic Operators

Here are some arithmetic operators supported by Tableau. All these operators act only on the numeric data type.
• Multiplication (*): we can multiply two numbers by the help of multiplication operator.
Example: 5 * 2 = 10
• Division (/): we can divide two numbers by the help of the division operator.
Example: 15 / 5 = 3
• Modulo (%): modulo operator gives you the remainder of the numeric division.
Example: 17 % 2 = 1
• Power (^): raised to the power.
Example: 2 ^ 2 = 4

3. Relational Operators

Here are the relational operators supported by Tableau. These operators are used in the expressions. Each relational operator compares two numbers, strings, or dates and returns a Boolean value (True or False).
However, Boolean operators themselves cannot be compared using these operators.
• Equal to (= or = =): It compares two numbers, strings or two dates to be similar and returns the Boolean values, true if they are equal else returns False.
Example: ‘hello’ = ‘hello’, returns True
‘2’ = ’10/5′, returns True
‘Hello’ = ‘hey’, returns False
• Not equal to (! = or <>): It compares two numbers, two strings, or dates to be unequal. And returns the Boolean values, true if they are equal else returns False.
Example: ‘cold’ <> ‘hot’
’13’ != ’24/2′
• Greater than (>): It compares two numbers, two strings or two dates where the first argument is greater than second, it Returns the Boolean value True else returns False.
Example: [Profit] > 10000
[Category] > ‘Q’
[Ship date] > #April 1, 2018#
• Less than (<): It compares two numbers, two strings or two dates, where the first argument is smaller than the second. It returns the Boolean value True, else returns false.
Example: [Profit] < 10000
[Category] < ‘Q’
[Ship date] < #April 1, 2018#

4. Logical operators

Here are the logical operators supported by Tableau. These operators are used in an expression whose result is a Boolean value (True or False).
• AND: If the Boolean values present on both sides of AND operator is evaluated to be TRUE, then the result is TRUE. Else the result is FALSE.
Example: [Ship Date] > #April 1, 2018# AND [Profit] > 20000
• OR: If anyone or both of the Boolean values present on both sides of the OR operator analyses to be TRUE, then the result is TRUE. Else the result is FALSE.
Example: [Ship Date] > #April 1, 2018# OR [Profit] > 20000
• NOT: This operator reverses the Boolean value of the expression.
Example: NOT [Ship Date] > #April 1, 2018#

Precedence of Operator

The below table is describing the order of precedence of the operator. The top row of below table has the highest precedence. Some operators in the same row have the same precedence.
If two operators have the same precedence, they are analyzed from left to the right in the formula. Parentheses can also be used in the same order, and the inner parentheses are evaluated before the outer parentheses.

Order of Precedence Operators
1 -(negate)
2 ^(power)
3 *, /, %
4 +, –
5 ==, >, <, >=, <=, !=
6 NOT
7 AND
8 OR

Tableau Functions

Data analysis involves a lot of calculations. In Tableau, the calculation editor has applied calculations to the fields being analyzed. Tableau has multiple inbuilt functions which help in creating expressions for complex calculations.
There is a list of Tableau functions that are categorized into five parts:
1. Number functions
2. String functions
3. Date functions
4. Logical functions
5. Aggregate functions

1. Number Functions

Number function is a function that uses for the numeric calculations. They take only numbers as inputs.
Let’s see some essential examples of number functions:
• Ceiling (Number): It rounds a number to the nearest integer of equal or greater values.
Example: CEILING (4.155) = 5
• Power (Number, Power): It raises the number to the specified power.
Example: POWER (2^3) = 8
• Round (Number, Decimals): It rounds the number to a specified number of digits.
Example: ROUND (5.14522) = 5.14

2. String Functions

String functions are used for the manipulation of the string.
Let’s see some essential examples of string functions:
• LEN (String): LEN string returns the length of the string.
Example: LEN (“Tableau”) = 7
• LTrim (String): It returns a string that contains a copy of the specified string with no leading (LTrim) or trailing (RTrim) spaces.
Example: LTrim (” Tableau “) = “Tableau”
• REPLACE (String, Substring Replacement): It searches the string for substring and replaces it. If the substring is not found, that string is not changed.
Example: REPLACE (“Green yellow Green”, “yellow”, “Red”) = “Green Red Green”
• UPPER (String): It returns the string with all uppercase characters.
Example: UPPER (“Tableau”) = “TABLEAU”

3. Date Functions

Tableau has many date functions, and all the date functions use the date_part, this is the string indicating part of the date such as day, month, or year.
Let’s see some essential examples of date functions:
• DATEADD (date_part, increment, date): It’s added an increment to the date. The type of increment is specified in the date_part.
Example: DATEADD (‘month’, 5, #2018-06-15#) = 2018-11-15 01:00:00 AM
• DATENAME (date_part, date, start_of_week): It returns date_part of date as a string. And the start_of_week parameter is optional.
Example: DATENAME (‘month’, #2018-03-15#) = “March”
• DAY (date): It returns the day of the given date in integer form.
Example: DAY (#2018-04-12#) = 12
• NOW (): It returns the current time and date.
Example: NOW ( ) = 2018-04-15 1:08:21 PM

4. Logical Functions

These functions evaluate some single values and produce a Boolean output.
See some essential examples of logical function:
• IFNULL (expression1, expression2): If the result is not null, then IFNULL function returns the first expression, and if it is null, then it returns the second expression.
Example: IFNULL ([Sales], 0) = [Sales]
• ISDATE (string): If the string argument can be converted to a date, the ISDATE function returns TRUE, and if it cannot, it returns FALSE.
Example: ISDATE (“12/06/99”) = “TRUE”
ISDATE (“14/06/99”) = “FALSE”
• MIN (expression): The MIN function returns the minimum result for each record.

5. Aggregate Functions

Let’s see some essential examples of aggregate functions:
• AVG (expression): It returns the average of all the values in the expression. AVG is used only with numeric fields. And the Null values are ignored.
• COUNT (expression): It returns the number of items in a group. And the Null values are not counted.
• MEDIAN (expression): It returns the median of an expression over all records. Median can only be used with numeric fields, and Null values are ignored.
• STDEV (expression): It returns the statistical standard deviation of all values in the given expression based on a sample of the population.

So, this brings us to the end of blog. This Tecklearn ‘Perform Calculation and Operators and Functions 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 "Perform Calculation and Operators and Functions in Tableau"

Leave a Message

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