Aggregations in
Tableau Calculations
Master the four essential aggregation functions: \( \text{SUM} \), \( \text{AVG} \), \( \text{COUNT} \), and \( \text{COUNTD} \) and learn how to use them correctly inside calculated fields.
What Is an Aggregation?
An aggregation is a function that takes many rows of data and reduces them to a single value. When you drag a measure onto a Tableau view, Tableau automatically wraps it in an aggregation: usually \( \text{SUM} \).
The Big Four Aggregations
Why Aggregations Matter
Tableau operates at two levels: the row level (each individual record) and the aggregate level (summarized groups). Every visualization you build works at the aggregate level. Understanding this distinction unlocks the ability to write correct calculated fields.
The Golden Rule
SUM([Sales]) / [Quantity]
// ✓ CORRECT: both aggregated
SUM([Sales]) / SUM([Quantity])
// ✓ CORRECT: neither aggregated (row-level)
[Sales] / [Quantity]
Dimensions Control Granularity
Aggregation results change depending on which dimensions are in the view. Adding a dimension splits the aggregation into smaller groups. This is called the level of detail (LOD).
\( \text{COUNT} \) vs \( \text{COUNTD} \)
\( \text{SUM} \) vs \( \text{AVG} \): When to Use Each
SUM([Sales])
// Average discount per order
AVG([Discount])
How to Write an Aggregated Calculation
Example 1: Profit Ratio
Goal: Calculate the profit ratio (profit as a percentage of sales) for each region.
SUM([Profit]) / SUM([Sales])
Example 2: Average Order Value
Goal: Calculate the average revenue per order for each product category.
SUM([Sales]) / COUNTD([Order ID])
Example 3: Percent of Total
Goal: Show each category's sales as a percentage of the grand total.
SUM([Sales]) / TOTAL(SUM([Sales]))
Row-Level vs Aggregate Calculations
| Row-Level | Aggregate | |
|---|---|---|
| Computed at | Each individual row | Group of rows |
| Syntax | \( \text{[Field A]} / \text{[Field B]} \) | \( \text{SUM}(\text{[A]}) / \text{SUM}(\text{[B]}) \) |
| When to use | Per-record metrics | Summary metrics |
| Example | \( \text{[Unit Price]} \times \text{[Quantity]} \) | \( \text{SUM}(\text{[Sales]}) / \text{COUNT}(\text{[Orders]}) \) |
| Result type | New data column | Aggregate measure |
Common Mistakes
Summary of Aggregation Functions
| Function | Returns | Best For | Watch Out |
|---|---|---|---|
| \( \text{SUM} \) | Total of all values | Revenue, Profit, Qty | Doesn't work for ratios |
| \( \text{AVG} \) | Arithmetic mean | Ratings, Temperatures | Unweighted: misleading for ratios |
| \( \text{COUNT} \) | Number of non-null rows | Total records, events | Includes duplicates |
| \( \text{COUNTD} \) | Number of unique values | Unique customers, IDs | Slower on large datasets |
Question 1 of 5
What will Tableau do if you write \( \text{SUM}(\text{[Sales]}) / \text{[Quantity]} \) in a calculated field?
Question 2 of 5
You have an orders table where each row is a line item. A single order can have multiple line items. Which formula correctly counts the number of unique orders?
Question 3 of 5
You want the profit ratio for each product category. Which calculated field is most appropriate?
Question 4 of 5
Adding the Region dimension to a view that shows \( \text{SUM}(\text{[Sales]}) \) will:
Question 5 of 5
A calculated field uses \( \text{[Unit Price]} \times \text{[Quantity]} \) with no aggregation functions. What type of calculation is this?