0% found this document useful (0 votes)
2 views

Module 3 Notes

The document outlines the curriculum for the Data Visualization Using Tableau course, focusing on data connections, calculations, and field operations. It covers key concepts such as data extraction, joining, blending, sorting, and various Tableau functions and operators. Additionally, it details the types of joins and the components of Tableau calculations, providing examples for better understanding.

Uploaded by

user-256473
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Module 3 Notes

The document outlines the curriculum for the Data Visualization Using Tableau course, focusing on data connections, calculations, and field operations. It covers key concepts such as data extraction, joining, blending, sorting, and various Tableau functions and operators. Additionally, it details the types of joins and the components of Tableau calculations, providing examples for better understanding.

Uploaded by

user-256473
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

AI&DS Dept.

Data Visualization Using Tableau (22ADS61) 2024-25

Module 3

Contents

Chapter 1:
• Data connection: Extracting data
• Joining
• Blending
• Sorting
• Fields operations

Chapter 2:
• Tableau calculations: Operators
• Functions
• Numeric
• String
• Date
• Table calculations
• Level of Details expressions

1
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

Chapter 1:
DATA CONNECTIONS

1.1. DATA CONNECTION: EXTRACTING DATA

In Tableau, Data extraction creates a subset of data from the data source. Data
extraction is useful for increasing the performance by applying filters. Data
extract feature is the most commonly used to create a local drive for offline access
by Tableau
Creating an Extract
Extraction of the data is done by following the menu:
Data → Extract Data.
It creates multiple options such as applying limits to how many rows to extract
and whether to aggregate data for dimensions.
The below figure shows the Extract Data option.

2
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

1.2. TABLEAU DATA JOINING


Data joining is a common requirement in any data analysis.
One may need to join data from different tables in a single source or join data
from multiple sources.
Tableau provides the feature to join the tables by using the data pane that is
available in the Data menu.
A join means combining columns from one or more tables in a relational database.
A join section is used to combine rows from two or more tables, based on a related
column between them.

Steps to create join


To create a join, connect to the relevant data source or sources.
Drag the first table to the canvas.
Select Open from the menu
Double-click or drag another table to the join canvas.
Click the join icon to configure the join
When finished, close the join dialog and join canvas.

3
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

4
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

5
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

Joins are specified into five types:


1. Cross Join
2. Inner Join
3. Natural Join
4. Outer Join
i. Left Outer Join
ii. Right Outer Join
iii. Full Outer Join
5. Self-Join

1. Cross Join: Cross join produces rows which combine each row from the first
table with each row from the second table.

2. Inner Join: An inner join returns the matching rows from the tables that are
being joined.

6
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

3. Natural Join: A Natural Join can be performed if there is at least one common
attribute that exists between two relations. Also, the attributes must have the
same name and domain. Natural join works on those matching attributes where
the values of attributes in both, the relation are same.
4. Outer Join: An outer join is an extended form of the inner join. It returns both
matching and non-matching rows for the tables that are being joined.
Types of outer joins are as follows:
i) Left Outer Join: The left outer join returns matching rows from the
tables being joined, and non-matching rows from the left table in the
result and places NULL values in the attributes that come from the right
table.

7
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

ii) Right Outer Join: The right outer join operation returns matching rows
from the tables being joined, and non-matching rows from the right
table in the result and places NULL values in the attributes that come
from the left table

iii) Full Outer Join: The full outer join is used to combine tables. As a
result, it contains all values from both tables. When a value from a table
doesn't have a match with the other table, then it returns a NULL value
in the data grid.

5. Self-Join: The self-join is used to join a table with itself. It means that each
row of the table is combined with itself as well as with every other row of the
table.

8
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

1.3. DATA BLENDING


Data Blending is a powerful feature of Tableau. It is used to analyze the data in a
single view from a related data in multiple data source.
Example: Suppose a Sales data is present in a relational database and Sales Target
data in an Excel sheet.
Now, for comparing the actual sales with the target sales, you have blended the
data based on common dimensions to get access into the Sales Target measure.
The two data sources that are involved in data blending are referred as the primary
data source and the secondary data source.

1.4. DATA SORTING


In the data source, data can be stored based on the user requirement. It can be
sorted using data source order such as A to Z ascending, Z to A descending, A to
Z ascending per table and Z to A descending per table.
Once the data is connected with Tableau, data sorting is done using the Sort
Fields option. The Sort Fields option is present in the Data Source tab.
There are two ways to sort the data in Tableau:
Manual sorting: Manual sorting is a sort that rearranges the order of dimension
fields by dragging them next to each other in ad hoc fashion.
Computed sorting: The computed sorting is a sort which is directly applied on the
axis using the sort dialog button.

1.5. FIELDS OPERATIONS


Tableau has many features to manipulate the fields present in Tableau data pane.
One can rename the fields or combine two fields to create one field. Such
operations help in better organization of the dimensions and measures, as well as
accommodate two or more fields with the same name for better data analysis.
Following are the important examples of such Field Operations:
a) Adding Fields to Worksheet
b) Combining Two Fields
c) Searching Fields
d) Reordering Fields

9
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

Chapter 2

1.6. COMPONENTS OF TABLEAU CALCULATION


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 that can be used in Tableau calculations
are +, -, *, /, %, ==, =, >, <, >=, <=, ! =, <>, ^, AND, OR, NOT, ( )

4. Literal Expression: Literal expressions are constant values that are


represented as any of the following five types.
For Example:
IF [Profit per Day] > 5000 THEN "Highly Profitable"
ELSEIF [Profit per Day] <= 0 THEN "Unprofitable"
ELSE "Profitable"
END

Types of Literals:
• 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"
10
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

• Null literals are written as null.


Example: "NULL"

Two more calculations contained by Tableau:

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]

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:
SUM ([Sales]) / SUM ([Profit]) // Nick's calculation
// to be used for profit ratio
// Do not edit

11
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

1.7. TABLEAU FUNCTIONS


Syntax ABS(number)

Output Number (positive)

Definition Returns the absolute value of the


given <number>.

Example ABS(-7) = 7
ABS([Budget Variance])The second example
returns the absolute value for all the numbers
contained in the Budget Variance field

Syntax ASCII(string)

Output Number

Definition Returns the ASCII code for the first character of


a <string>.

Example ASCII('A') = 65

1.8. 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.
Types of operators:
General operators
Arithmetic operators
Relational operators
Logical operators

12
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

1. General Operators
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
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 the remainder of the numeric division.
Example: 17 % 2 = 1
Power (^): raised to the power.
Example: 2 ^ 2 = 4

3. Relational Operators
These operators are used in the expressions. Each relational operator compares
two numbers, strings, or dates and returns a Boolean value (True or False).
Boolean operators themselves cannot be compared using these operators.

13
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

• 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
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 any 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#
14
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

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

15
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

1.9 Tableau Functions


Data analysis involves a lot of calculations. 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 is used for the numeric calculations. They take
only numbers as inputs.
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, 3) = 5.145
2. String Functions
String functions are used for the manipulation of the string.
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

16
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

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.
Examples of date functions:
• DATEADD (date_part, increment, date): Used to add 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
• 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.
Examples of logical functions:
• 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“
• MIN (expression): The MIN function returns the minimum result for each
record.

17
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

5. Aggregate Functions
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 exression. Null values are ignored.

1.10 Tableau Calculations


In Tableau numeric, string, date, table calculations are done using a wide range
of inbuilt functions available in the formula editor.
Here are the steps to create a calculation field and use functions in it.
a) How to Create a Calculated Field
• Connect to a data source such as Sample-Superstore.
• Go to Analysis menu.
• And click on Create Calculated Field as shown in the below image.

18
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

b) Calculation Editor in Tableau


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

One can change the dropdown value and only see the related functions.

19
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

c) Create a Formula
To 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.

d) 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.

20
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

1.11 Tableau LOD Expressions


LOD (level of Details) expression is used to run complex queries involving many
dimensions at the data sources instead of bringing all the data to the Tableau
interface.
A level of detail expression has the following syntax/structure:
The entire level of detail expression is enclosed in curly braces

The first element after the opening curly brace is one of the following scoping
keywords: [FIXED | INCLUDE | EXCLUDE]
a) FIXED LOD:
This LOD expression computes the values using the specified dimensions without
reference to any other dimensions in the view.
FIXED level of detail expressions ignore all the filters in the view other than
context filters, data source filters, and extract filters.

21
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25

The above FIXED level of detail expression computes the sum of sales per region.
b) INCLUDE LOD:
This LOD expression computes the values using the specified dimensions in
addition to whatever dimensions are in the view.
INCLUDE level of detail expressions are most useful when including a
dimension that isn’t in the view.

The above INCLUDE level of detail expression computes total sales per
customer.
c) EXCLUDE LOD:
These LOD expressions explicitly remove dimensions from the expression—that
is, they subtract dimensions from the view level of detail.
EXCLUDE level of detail expressions are most useful for eliminating a
dimension in the view.

The above example creates a level of detail expression, named "ExcludeRegion",


that excludes [Region] from the sum of [Sales].

***

22

You might also like