Module 3 Notes
Module 3 Notes
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
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
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
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
9
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25
Chapter 2
Types of Literals:
• Numeric literals are written as numbers.
Example: 27 or 1.3567
11
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25
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
Example ASCII('A') = 65
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
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.
1 -(negate)
2 ^(power)
3 *, /, %
4 +, -
6 NOT
7 AND
8 OR
15
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25
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.
18
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25
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.
20
AI&DS Dept. Data Visualization Using Tableau (22ADS61) 2024-25
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.
***
22