0% found this document useful (0 votes)
17 views16 pages

U3 - Tableau

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

U3 - Tableau

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

Unit 3

Prepared by: Varun Rao (Dean, Data Science & AI)


For: Data Science - 2nd years

Predefined Aggregations in Tableau


Sometimes it is useful to look at numerical data in an aggregated form such as
a summation or an average. The mathematical functions that produce
aggregated data are called aggregation functions. Aggregation functions
perform a calculation on a set of values and return a single value.

AGGREGATION DESCRIPTION RESULT FOR MEASURE


THAT CONTAINS 1, 2, 2,
3

Attribute N/A
Returns the value of the
given expression if it
only has a single value
for all rows in the group,
otherwise it displays an
asterisk (*) character.
Null values are ignored.
This aggregation is
particularly useful when
aggregating a
dimension. To set a
measure in the view to
this aggregation, right-
click (control-click on
Mac) the measure and
choose Attribute. The
field then changes to
show the text ATTR:

Dimension Returns all unique 3 values (1, 2, 3)


values in a measure or
dimension.

Sum Returns the sum of the 1 value (8)


numbers in a measure.
Null values are ignored.

Average Returns the arithmetic 1 value (4)


mean of the numbers in
a measure. Null values
are ignored.

Count (Distinct) 1 value (3)


Returns the number of
unique values in a
measure or dimension.
When applied to a
dimension, Tableau
creates a new temporary
column that is a
measure because the
result of a count is a
number. You can count
numbers, dates,
booleans, and strings.
Null values are ignored
in all cases.

This aggregation is not


available for the
following types of
workbooks:

● Workbooks
created before
Tableau Desktop
8.2 and that use
Microsoft Excel or
Text File data
sources.
● Workbooks that
use legacy
connections.
● Workbooks that
use Microsoft
Access data
sources.

If you are connected to a


workbook that uses of
one of these types,
Count (Distinct) is
unavailable and Tableau
shows the message
"Requires extract." To
use this aggregation,
extract your data. See
Extract Your Data.

Minimum Returns the smallest 1 value (1)


number in a measure or
continuous dimension.
Null values are ignored.

Maximum Returns the largest 1 value (3)


number in a measure or
in the given expression
based on a sample
population. Null values
are ignored. Returns a
Null if there are fewer
than 2 members in the
sample that are not Null.
Use this function if your
data represents a
sample of the
population.

Std. Dev (Pop.) Returns the standard 1 value (0.7071)


deviation of all values in
the given expression
based on a biased
population. Assumes
that its arguments
consist of the entire
population. Use this
function for large
sample sizes.

Variance Returns the variance of 1 value (0.6667)


all values in the given
expression based on a
sample. Null values are
ignored. Returns a Null
if there are fewer than 2
members in the sample
that are not Null. Use
this function if your
data represents a
sample of the
population.

Variance (Pop.) Returns the variance of 1 value (0.5000)


all values in the given
expression based on a
biased population.
Assumes that its
arguments consist of
the entire population.
Use this function for
large sample sizes.

Calculated Values and Table Calculations

Calculated Values and Table Calculations allow you to add new data to your Tableau
workbook, but the way you add the data, and where the calculations occur, is different for
each method. Use table calculation functions to customize table calculations. They are
computations/calculations that are applied to the values in the entire table and are
often dependent on the table structure itself.

Calculated Values are defined by entering a formula into Tableau’s formula editing dialog
box. For example, if you have gross margin dollars and sales dollars in your source data,
you may want to add a new field called Gross Margin Percent by creating a calculated
value. The formula to create the gross margin percent is: sum ([ gross margin dollars]) /
sum ([ sales dollars]).

Table Calculations:
Table calculations are the computational workhorse of Tableau. Table calculations are
derived from the structure of the data included in your visualization, so table calculations are
dependent on the source worksheet view contained in your workbook. That means these
calculations are always derived locally by using your personal computer’s processor to
return the result.

Understanding exactly how Table Calculations work takes a little time because Table
Calculations can change as your visualization is altered. As with any new concept, after you
create some Table Calculations you’ll get comfortable with how they behave in different
situations. Tableau’s online manual has a large number of examples where you can view
and get some good basic introduction.

Creating a Table Calculation requires that you have a worksheet with a visualization. A
good way to create them is to right-click on a measure pill used in the view to expose the
Quick Table Calculation menu. Quick Table Calculations are provided for:

● Running total
● Difference
● Percent difference
● Percent of total
● Moving average
● YTD total
● Compound growth rate
● Year over year growth
● YTD growth

Depending on the view of the data included in your worksheet some of these may be
unavailable because your worksheet view doesn’t support the calculation.

Calculated Values:
Calculated Values can be used to generate numbers, dates, date-times, or strings. All
calculated values require the following elements:

● Functions— including aggregate, number, string, date, type conversion,


logical, user and table calculation types
● Fields— selected from the data source
● Operators— for math and comparison of values, dates, and text
● Optional elements can be added within the formula dialog box including:
● Parameters— for creating formula variables that are accessible to information
consumers
● Comments— for documenting formula syntax and notes within the formula
dialog box

Start the formula dialog box via the main menu using the Analysis/ Created Calculated Field
option or by right-clicking on a field . The formula dialog is where you enter the functions,
operators, and parameters to create the logic for your formula. Alternatively, right-clicking a
field in the dimensions or measures, shelves opens the formula dialog box as well, but also
includes that field that is already entered in the formula editing area.

Using the Calculation Dialog Box to Create Calculated Values


Calculated Values require entering of fields, functions and operators. Tableau strives to
make formula creation fast and easy, so it is possible to write formulas with minimal typing.
Once you’ve connected to a data source, you can create a calculated field from the main
menu by selecting Analysis/ Create Calculated Field.

Calculated fields allow you to create new data from data that already exists in
your data source. When you create a calculated field, you are essentially
creating a new field (or column) in your data source, the values or members of
which are determined by a calculation that you control. This new calculated
field is saved to your data source in Tableau, and can be used to create more
robust visualizations.

You can use calculated fields for many, many reasons. Some examples might
include:

● To segment data
● To convert the data type of a field, such as converting a string to a date.
● To aggregate data
● To filter results
● To calculate ratios

You create calculated fields using calculations. There are three main types of
calculations you can use to create calculated fields in Tableau:
● Basic calculations - Basic calculations allow you to transform values or
members at the data source level of detail (a row-level calculation) or at
the visualization level of detail (an aggregate calculation).
● Level of Detail (LOD) expressions - Just like basic calculations, LOD
calculations allow you to compute values at the data source level and the
visualization level. However, LOD calculations give you even more
control on the level of granularity you want to compute. They can be
performed at a more granular level (INCLUDE), a less granular level
(EXCLUDE), or an entirely independent level (FIXED) with respect to the
granularity of the visualization.
● Table calculations - Table calculations allow you to transform values at
the level of detail of the visualization only.

The type of calculation you choose depends on the needs of your analysis
and the question you want to answer.

Step 1: Build the view

1. From Dimensions, drag Region to the Columns shelf.


2. From Dimensions, drag Category to the Rows shelf.
3. On the Rows shelf, click the plus icon (+) on the Category field to drill-
down to Subcategory.
The view updates to look like this:

Step 2: Add the calculated field to the view

1. From Measures, drag Discount Ratio to Color on the Marks card.


The view updates to highlight table.
You can see that Binders are heavily discounted in the Central region.
Notice that Discount Ratio is automatically aggregated as a sum.
2. On the Rows shelf, right-click SUM(Discount Ratio) and select Measure
(Sum) > Average.
The view updates with the average of the discount ratio shown.
Building formulas using table calculations
Click any field in the view to see a context menu listing ways to customize the
field. For a field in the view that has a table calculation, you can change the
Compute Using option—that is, the option that determines the direction and
scope of the calculation relative to the visual structure of the view. Do this by
clicking the field and then choosing an option from the Compute Using list.

For Difference From, Percent Difference From, and Percent From table
calculations, you can also specify a different field from which the difference
should be computed. The options are Previous, Next, First, and Last.

Build your Table Calculation Using the Calculation Editor


You can customize a table calculation by dragging it into the calculation editor:
When you edit a table calculation in the calculation editor, you can click
Default Table Calculation in the lower-right corner of the editor to open the
calculation in the Table Calculation dialog box. This will allow you to create a
new named calculated field that uses the same table calculation as the one you
are basing the calculation on.

Nested Table Calculations


A nested table calculation can be one of two types of calculated fields:

● A calculated field that includes more than one calculated field with a
table calculation (as in the example below), or
● A calculated field that itself has a table calculation and includes at least
one calculated field with a table calculation.

With nested table calculations, you can set Compute Using configurations for
individual calculations independently.

Here is a scenario you can try, using the Sample - Superstore data source that
is included with Tableau Desktop, which results in a nested table calculation.
1. Drag Sub-Category to Columns and Region to Rows.
2. Create a calculated field, 1-nest, with the definition
TOTAL(SUM([Sales])).
TOTAL is a table calculation function, so this calculated field
automatically has a table calculation—when you use it in the view, the
field will have the tell-tale table triangle, indicating a table calculation:

Create a second calculated field, 2-nest, with the definition


TOTAL(SUM([Profit])).
3. Create a third calculated field, 3-nest, with the definition [1-nest] +
[2-nest].
4. Drag 3-nest and drop it to the right of Sub-Category on Columns.
5. Click 3-nest on Columns and choose Edit Table Calculation.
In the Table Calculations dialog box, you can now separately configure
the underlying table calculations:

Using table calculation functions


Step 1: Create the visualization

1. In Tableau Desktop, connect to the Sample-Superstore saved data


source, which comes with Tableau.
2. Navigate to a worksheet.
3. From the Data pane, under Dimensions, drag Order Date to the Columns
shelf.
4. From the Data pane, under Dimensions, drag Sub-Category to the Rows
shelf.
5. From the Data pane, under Measures, drag Sales to Text on the Marks
card.
Your visualization updates to a text table.

Step 2: Create the table calculation

1. Select Analysis > Create Calculated Field.


2. In the calculation editor that opens, do the following:
○ Name the calculated field, Running Sum of Profit.
○ Enter the following formula:
RUNNING_SUM(SUM([Profit]))
This formula calculates the running sum of profit sales. It is
computed across the entire table.
○ When finished, click OK.
The new table calculation field appears under Measures in the Data
pane. Just like your other fields, you can use it in one or more
visualizations.

Step 3: Use the table calculation in the visualization

1. From the Data pane, under Measures, drag Running Sum of Profit to
Color on the Marks card.
2. On the Marks card, click the Mark Type drop-down and select Square.
The visualization updates to a highlight table:

Step 4: Edit the table calculation

1. On the Marks card, right-click Running Sum of Profit and select Edit
Table Calculation.
2. In the Table Calculation dialog box that opens, under Compute Using,
select Table (down).
The visualization updates to the following:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy