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

  1. 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.
  2. 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.
  3. 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

  1. 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.
  2. Apply a Running Total:

    • Right-click on the SUM(Sales) pill in the Rows shelf.
    • Select Quick Table Calculation > Running Total.
  3. 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).
# Visualization: Running Total of Sales by Month

Example 2: Custom Table Calculation - Percent of Total

  1. Create a Basic Visualization:

    • Drag the Category field to the Columns shelf.
    • Drag the Sales field to the Rows shelf.
  2. Apply a Percent of Total Calculation:

    • Right-click on the SUM(Sales) pill in the Rows shelf.
    • Select Quick Table Calculation > Percent of Total.
  3. 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).
# Visualization: Percent of Total Sales by Category

Exercises

Exercise 1: Create a Year-over-Year Growth Calculation

  1. 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.
  2. 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.
  3. 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).

Solution

# Visualization: Year-over-Year Growth of Sales

Exercise 2: Create a Moving Average Calculation

  1. 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.
  2. Apply a Moving Average Calculation:

    • Right-click on the SUM(Sales) pill in the Rows shelf.
    • Select Quick Table Calculation > Moving Average.
  3. Adjust the Calculation:

    • Right-click on the SUM(Sales) pill again.
    • Select Edit Table Calculation.
    • Set the Moving Calculation to Previous 3.

Solution

# Visualization: 3-Month Moving Average of Sales

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.

© Copyright 2024. All rights reserved