Table calculations in Tableau are powerful tools that allow you to perform complex computations on your data directly within your visualizations. They are computed based on the data in your view and can be used to create advanced metrics, rankings, running totals, and more. This section will guide you through the basics of using table calculations, including practical examples and exercises to solidify your understanding.
Key Concepts
-
Table Calculations Overview:
- Table calculations are performed on the data in your visualization.
- They are different from calculated fields, which are computed at the data source level.
-
Types of Table Calculations:
- Quick Table Calculations: Predefined calculations that can be applied with a few clicks.
- Custom Table Calculations: User-defined calculations that offer more flexibility.
-
Scope and Direction:
- Scope: Determines the subset of data the calculation is applied to (e.g., table, pane, cell).
- Direction: Defines the direction in which the calculation is applied (e.g., across, down).
Practical Examples
Example 1: Quick Table Calculation - Running Total
-
Create a Basic Visualization:
- Drag the
Order Date
field to the Columns shelf. - Drag the
Sales
field to the Rows shelf. - Change the
Order Date
to show the data by month.
- Drag the
-
Apply a Running Total:
- Right-click on the
SUM(Sales)
pill in the Rows shelf. - Select
Quick Table Calculation
>Running Total
.
- Right-click on the
-
Adjust the Calculation:
- Right-click on the
SUM(Sales)
pill again. - Select
Edit Table Calculation
. - Ensure the calculation is set to compute using
Table (Across)
.
- Right-click on the
Example 2: Custom Table Calculation - Percent of Total
-
Create a Basic Visualization:
- Drag the
Category
field to the Columns shelf. - Drag the
Sales
field to the Rows shelf.
- Drag the
-
Apply a Percent of Total Calculation:
- Right-click on the
SUM(Sales)
pill in the Rows shelf. - Select
Quick Table Calculation
>Percent of Total
.
- Right-click on the
-
Adjust the Calculation:
- Right-click on the
SUM(Sales)
pill again. - Select
Edit Table Calculation
. - Ensure the calculation is set to compute using
Table (Down)
.
- Right-click on the
Exercises
Exercise 1: Create a Year-over-Year Growth Calculation
-
Create a Basic Visualization:
- Drag the
Order Date
field to the Columns shelf. - Drag the
Sales
field to the Rows shelf. - Change the
Order Date
to show the data by year.
- Drag the
-
Apply a Year-over-Year Growth Calculation:
- Right-click on the
SUM(Sales)
pill in the Rows shelf. - Select
Quick Table Calculation
>Year over Year Growth
.
- Right-click on the
-
Adjust the Calculation:
- Right-click on the
SUM(Sales)
pill again. - Select
Edit Table Calculation
. - Ensure the calculation is set to compute using
Table (Across)
.
- Right-click on the
Solution
Exercise 2: Create a Moving Average Calculation
-
Create a Basic Visualization:
- Drag the
Order Date
field to the Columns shelf. - Drag the
Sales
field to the Rows shelf. - Change the
Order Date
to show the data by month.
- Drag the
-
Apply a Moving Average Calculation:
- Right-click on the
SUM(Sales)
pill in the Rows shelf. - Select
Quick Table Calculation
>Moving Average
.
- Right-click on the
-
Adjust the Calculation:
- Right-click on the
SUM(Sales)
pill again. - Select
Edit Table Calculation
. - Set the
Moving Calculation
toPrevious 3
.
- Right-click on the
Solution
Common Mistakes and Tips
- Incorrect Scope and Direction: Ensure you understand the scope and direction of your table calculations. Misconfiguring these can lead to incorrect results.
- Overlapping Calculations: Avoid applying multiple table calculations on the same field without understanding their combined effect.
- Performance Considerations: Complex table calculations can impact performance. Optimize your data and calculations where possible.
Conclusion
In this section, you learned about the basics of table calculations in Tableau, including how to apply quick table calculations and create custom ones. You also practiced creating running totals, percent of total calculations, year-over-year growth, and moving averages. Understanding and effectively using table calculations will enable you to perform advanced data analysis and create more insightful visualizations.
Next, we will delve into Advanced Visualization Techniques, where you will learn about advanced chart types, LOD expressions, and more.
Tableau Course
Module 1: Introduction to Tableau
- What is Tableau?
- Installing Tableau
- Tableau Interface Overview
- Connecting to Data Sources
- Basic Data Types and Structures
Module 2: Basic Visualization Techniques
- Creating Your First Visualization
- Using Marks and Cards
- Building Basic Charts
- Filtering Data
- Sorting and Grouping Data
Module 3: Intermediate Visualization Techniques
- Using Calculated Fields
- Creating Dual-Axis Charts
- Using Parameters
- Creating Maps
- Using Table Calculations
Module 4: Advanced Visualization Techniques
- Advanced Chart Types
- Using LOD Expressions
- Creating Dashboards
- Dashboard Actions
- Storytelling with Data
Module 5: Data Preparation and Transformation
Module 6: Advanced Analytics
Module 7: Performance Optimization
- Optimizing Workbook Performance
- Extracts vs Live Connections
- Reducing Load Times
- Performance Recording
- Best Practices for Performance
Module 8: Tableau Server and Online
- Introduction to Tableau Server
- Publishing Workbooks
- Managing Permissions
- Scheduling Extracts
- Collaborating with Tableau Online