📊

Introduction to Tableau Calculations

Jul 23, 2024

Introduction to Tableau Calculations

Overview

  • Target Audience: New to Tableau or need a refresher on calculations
  • Covered Topics: What calculations are, where to find them, how to create them, types of calculations, examples

What Are Calculations?

  • Extend your data source with logic, business rules, or existing data points
  • Types of Calculations in Tableau:
    • Basic Calculations
    • Level of Detail (LOD) Expressions
    • Table Calculations
  • Focus on Basic Calculations: Row Level Calculations and Aggregate Calculations

Components of Calculated Field

  • Name
  • Comments (optional)
  • Field Names (drag from sidebar)
  • String Literals (text embedded into calculation)
  • Operators (e.g., string concatenation using “+”)
  • Parameters
  • Functions (built-in reusable code)

Creating Calculated Fields

  1. Drop Down Menu
    • Under data source window
    • Opens calculated field editor
  2. Right-Click on Field
    • Select “Create Calculated Field”
  3. Menu: Analysis > Create Calculated Field
  4. Ad Hoc Calculations
    • Double-click empty area in columns/rows/marks card
    • Less feature-rich (no function list)
    • Limited to the current worksheet

Basic Calculations: Row Level

  • Row level calculation: Derives value for every row from the data source
  • Examples:
    • Email Domain Extraction
      • Use split or custom split
    • Full Name Creation
      • Concatenate first name, last name with operators
    • Conditional String Functions
      • Use functions like contains, starts with, ends with
      • Example: Identify tracks by U2/Bono using “contains”
    • Profit Identification
      • Field showing if each line item is profitable (Profit > 0)
    • Date Compositions
      • Use MAKEDATE to combine year, month, day fields
      • Use DATEPARSE for unconventional date formats
    • Date Calculations
      • Use DATEDIF to calculate intervals (e.g., days since invoice)

Basic Calculations: Aggregate

  • Aggregate functions: Generate one result for a group of records
  • Examples:
    • Counting distinct values
    • Sum, average, minimum, maximum of field values
  • Aggregation happens by default with measures grouped by dimensions
  • Creating Aggregated Calculated Fields
    • Example: COUNTD(Customer ID)
    • Example: Profit ratio calculation as aggregate (SUM(profit) / SUM(sales))

Practical Tips and Warnings

  • Ad Hoc Calculations: Limited feature set
  • Date Functions Differences: E.g., DATEDIF syntax is different between Tableau and SQL Server
  • Validation: Always double-check calculated field results
  • Aggregating First for Ratios: Important to aggregate (e.g., sum) before dividing to avoid incorrect values
  • Documentation: Add comments in calculated fields for clarity
  • Syntax Errors: Use Tableau's error hints to fix issues

Conclusion

  • Covered basics and practical examples of Tableau calculations
  • Stay tuned for future videos on LOD expressions and table calculations.