Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

6/14/2021 Types of Calculations in Tableau - Tableau

Types of Calculations in Tableau


Version: 2021.1

Applies to: Tableau Desktop, Tableau Online, Tableau Server

This article explains the types of calculations you can use in Tableau. You'll
learn the difference between each calculation and how they are computed.

There are three main types of calculations you can use to create calculated
fields in Tableau:

Basic expressions

Level of Detail (LOD) expressions

Table calculations

Basic expressions

Basic expressions 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).

For example, consider the following sample table, which contains data on two
fantasy authors and their books. Perhaps you want to create a column with
only the author's last name and a column that displays how many books are in
each series.

Book ID Book Name Series Year Released Author

https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_types.htm 1/16
6/14/2021 Types of Calculations in Tableau - Tableau

1 The Lion, the The 1950 C.S. Lewis


Witch and the Chronicles of
Wardrobe Narnia

2 Prince The 1951 C.S. Lewis


Caspian: The Chronicles of
Return to Narnia
Narnia

3 The Voyage of The 1952 C.S. Lewis


the Dawn Chronicles of
Treader Narnia

4 The Silver The 1953 C.S. Lewis


Chair Chronicles of
Narnia

5 The Horse The 1954 C.S. Lewis


and His Boy Chronicles of
Narnia

6 The The 1955 C.S. Lewis


Magician's Chronicles of
Nephew Narnia

7 The Last The 1956 C.S. Lewis


Battle Chronicles of
Narnia

8 Daughter of Sevenwaters 1999 Juliet


the Forest Marillier

https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_types.htm 2/16
6/14/2021 Types of Calculations in Tableau - Tableau

9 Son of the Sevenwaters 2000 Juliet


Shadows Marillier

10 Child of the Sevenwaters 2001 Juliet


Prophecy Marillier

11 Heir of Sevenwaters 2008 Juliet


Sevenwaters Marillier

12 Seer of Sevenwaters 2010 Juliet


Sevenwaters Marillier

13 Flame of Sevenwaters 2012 Juliet


Sevenwaters Marillier

Row-level calculations

To create a column that displays the author's last name for every row in the
data source, you can use the following row-level calculation that splits on a
space:

SPLIT([Author], '', 2 )

The result can be seen below. The new column, titled Author Last Name is
shown on the far right. The colors demonstrate the level of detail the
calculation is performed at. In this case, the calculation is performed at the
row-level of the data source, so each row is colored separately.

Book ID Book Series Year Author Author


Name Released Last Name

https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_types.htm 3/16
6/14/2021 Types of Calculations in Tableau - Tableau

1 The Lion, The 1950 C.S. Lewis Lewis


the Witch Chronicles
and the of Narnia
Wardrobe

2 Prince The 1951 C.S. Lewis Lewis


Caspian: Chronicles
The Return of Narnia
to Narnia

3 The Voyage The 1952 C.S. Lewis Lewis


of the Chronicles
Dawn of Narnia
Treader

4 The Silver The 1953 C.S. Lewis Lewis


Chair Chronicles
of Narnia

5 The Horse The 1954 C.S. Lewis Lewis


and His Chronicles
Boy of Narnia

6 The The 1955 C.S. Lewis Lewis


Magician's Chronicles
Nephew of Narnia

7 The Last The 1956 C.S. Lewis Lewis


Battle Chronicles
of Narnia

https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_types.htm 4/16
6/14/2021 Types of Calculations in Tableau - Tableau

8 Daughter Sevenwater 1999 Juliet Marillier


of the s Marillier
Forest

9 Son of the Sevenwater 2000 Juliet Marillier


Shadows s Marillier

10 Child of Sevenwater 2001 Juliet Marillier


the s Marillier
Prophecy

11 Heir of Sevenwater 2008 Juliet Marillier


Sevenwater s Marillier
s

12 Seer of Sevenwater 2010 Juliet Marillier


Sevenwater s Marillier
s

13 Flame of Sevenwater 2012 Juliet Marillier


Sevenwater s Marillier
s

Aggregate calculations

To create a column that displays how many books are in each series, you can
use the following aggregate calculation:

COUNT([Series])

https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_types.htm 5/16
6/14/2021 Types of Calculations in Tableau - Tableau

The result can be seen below. The new column, titled Number of Books in
Series - at Series level of detail shows how that calculation would be
performed at the Series level of detail in the view. The colors help demonstrate
the level of detail in which the calculation is being performed.

Series Number of Books in Series - at


Series level of detail

The Chronicles of Narnia 7

The Chronicles of Narnia

The Chronicles of Narnia

The Chronicles of Narnia

The Chronicles of Narnia

The Chronicles of Narnia

The Chronicles of Narnia

Sevenwaters 6

Sevenwaters

Sevenwaters

Sevenwaters

Sevenwaters

Sevenwaters

In Tableau, the data looks like this:

https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_types.htm 6/16
6/14/2021 Types of Calculations in Tableau - Tableau

But if you drag in Book Id, (which is a more granular field), the calculation
updates based on that new granularity since aggregate calculations are
performed at the visualization level of detail.

https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_types.htm 7/16
6/14/2021 Types of Calculations in Tableau - Tableau

Level of Detail (LOD) expressions

Just like basic expressions , LOD expressions allow you to compute values at
the data source level and the visualization level. However, LOD expressions
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).

For more information, see Create Level of Detail Expressions in Tableau .

For example, consider the same sample table as above. If you wanted to
compute when a book series was launched, you might use the following LOD
expression:

{ FIXED [Series]:(MIN([Year Released]))}

The result can be seen below. The new column, titled Series Launched,
displays the minimum year for each series. The colors help demonstrate the
level of detail in which the calculation is being applied.

Book ID Book Series Year Author Series


Name Released Launched

1 The Lion, The 1950 C.S. Lewis 1950


the Witch Chronicles
and the of Narnia
Wardrobe

https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_types.htm 8/16
6/14/2021 Types of Calculations in Tableau - Tableau

2 Prince The 1951 C.S. Lewis 1950


Caspian: Chronicles
The Return of Narnia
to Narnia

3 The Voyage The 1952 C.S. Lewis 1950


of the Chronicles
Dawn of Narnia
Treader

4 The Silver The 1953 C.S. Lewis 1950


Chair Chronicles
of Narnia

5 The Horse The 1954 C.S. Lewis 1950


and His Chronicles
Boy of Narnia

6 The The 1955 C.S. Lewis 1950


Magician's Chronicles
Nephew of Narnia

7 The Last The 1956 C.S. Lewis 1950


Battle Chronicles
of Narnia

8 Daughter Sevenwater 1999 Juliet 1999


of the s Marillier
Forest

9 Son of the Sevenwater 2000 Juliet 1999


Shadows s Marillier

https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_types.htm 9/16
6/14/2021 Types of Calculations in Tableau - Tableau

10 Child of Sevenwater 2001 Juliet 1999


the s Marillier
Prophecy

11 Heir of Sevenwater 2008 Juliet 1999


Sevenwater s Marillier
s

12 Seer of Sevenwater 2010 Juliet 1999


Sevenwater s Marillier
s

13 Flame of Sevenwater 2012 Juliet 1999


Sevenwater s Marillier
s

In Tableau, the calculation remains at the Series level of detail since it uses the
FIXED function.

https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_types.htm 10/16
6/14/2021 Types of Calculations in Tableau - Tableau

If you add another field to the view (which adds more granularity) the values
for the calculation are not affected, unlike an aggregate calculation.

Table calculations

Table calculations allow you to transform values at the level of detail of the
visualization only.

For more information, see Transform Values with Table Calculations .

For example, consider the same sample table as above. If you wanted to
compute the number of years since the author released their last book, you
might use the following table calculation:

ATTR([Year Released]) - LOOKUP(ATTR([Year Released]), -1)

https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_types.htm 11/16
6/14/2021 Types of Calculations in Tableau - Tableau

The result is shown below. The new column, titled Years Since Previous Book,
displays the number of years between the book released in that row and the
book released in the previous row (on the far right-side of the column) and
demonstrates how the table calculation is being computed (on the left-side of
the column).

The colors help demonstrate how the table calculation is being computed. In
this case, the table calculation is being computed down each pane.

Note: Depending on the table calculation and how it is being computed


across the table, the results may vary. For more information, see
Transform Values with Table Calculations .

Book ID Book Series Year Author  Years Since Previous Book


Name Release
d

1 The The 1950 C.S. NULL  


Lion, Chronic Lewis
the les of
Witch Narnia
and the
Wardro
be

https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_types.htm 12/16
6/14/2021 Types of Calculations in Tableau - Tableau

2 Prince The 1951 C.S. 1951- 1950 1


Caspian Chronic Lewis
: The les of
Return Narnia
to
Narnia

3 The The 1952 C.S. 1952- 1951 1


Voyage Chronic Lewis
of the les of
Dawn Narnia
Treader

4 The The 1953 C.S. 1953- 1952 1


Silver Chronic Lewis
Chair les of
Narnia

5 The The 1954 C.S. 1954- 1953 1


Horse Chronic Lewis
and His les of
Boy Narnia

6 The The 1955 C.S. 1955- 1954 1


Magicia Chronic Lewis
n's les of
Nephew Narnia

https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_types.htm 13/16
6/14/2021 Types of Calculations in Tableau - Tableau

7 The The 1956 C.S. 1956- 1955 1


Last Chronic Lewis
Battle les of
Narnia

8 Daught Sevenw 1999 Juliet NULL  


er of aters Marillie
the r
Forest

9 Son of Sevenw 2000 Juliet 2000- 1999 1


the aters Marillie
Shadow r
s

10 Child of Sevenw 2001 Juliet 2001- 2000 1


the aters Marillie
Prophec r
y

11 Heir of Sevenw 2008 Juliet 2008- 2001 7


Sevenw aters Marillie
aters r

12 Seer of Sevenw 2010 Juliet 2010- 2008 2


Sevenw aters Marillie
aters r

https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_types.htm 14/16
6/14/2021 Types of Calculations in Tableau - Tableau

13 Flame Sevenw 2012 Juliet 2012- 2010 2


of aters Marillie
Sevenw r
aters

In Tableau, the data looks like this:

However, if you change the visualization in a way that affects the layout, such
as removing a dimension from the view, the calculation values change.

For example, in the image below, Author is removed from the viz. Since the
table calculation is computed by pane, removing Author changes the
granularity and layout of the viz (instead of two panes there is now only one).
The table calculation therefore calculates the time between 1956 and 1999.

https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_types.htm 15/16
6/14/2021 Types of Calculations in Tableau - Tableau

Continue to Choosing the Right Calculation Type


(calculations_calculatedfields_understand_which.htm)

See Also

Understanding Calculations in Tableau

Tips for Learning How to Create Calculations

https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_understand_types.htm 16/16

You might also like