INCLUDE / EXCLUDE
LOD Expressions
Master Level of Detail calculations in Tableau to control granularity independently of your viz dimensions.
What is Granularity?
Granularity is the level of detail at which your data is aggregated. In Tableau, it is determined by the dimensions on your Rows, Columns, and other shelves. Each unique combination of dimension values creates one mark (data point) in the view.
The LOD Problem
Sometimes you need a calculation at a different granularity than your view provides. For example: your viz shows sales per Sub-Category, but you want to compare each Sub-Category to the Category-level average.
The LOD Expression Family
Tableau offers three LOD expression types. Today we focus on INCLUDE and EXCLUDE: the two that modify the view's granularity.
The INCLUDE Expression
{ INCLUDE [Dimension] : AGG(expression) }
INCLUDE takes the view's current dimensions and adds the specified dimension before computing the aggregate. The result is then re-aggregated at the view level.
INCLUDE Adds Granularity
The EXCLUDE Expression
{ EXCLUDE [Dimension] : AGG(expression) }
EXCLUDE takes the view's current dimensions and removes the specified dimension before computing the aggregate. The coarser result is then replicated across every mark.
EXCLUDE Removes Granularity
INCLUDE vs EXCLUDE
| INCLUDE | EXCLUDE | |
|---|---|---|
| Direction | Finer (adds detail) | Coarser (removes detail) |
| Modifies view by | Adding a dimension | Removing a dimension |
| Result type | Measure (must re-aggregate) | Measure (replicated per mark) |
| Use when... | You need a sub-level metric | You need a parent-level metric |
| Classic use case | Avg. orders per customer | % of category total |
How to Build an LOD Expression
Example 1: Average Orders per Customer
Goal: Show the average number of orders per customer for each Region. The view has only Region on Rows, but "orders per customer" requires the Customer dimension.
{ INCLUDE [Customer Name] : COUNTD([Order ID]) }
// Step 2: Place on the view, wrap in AVG
AVG({ INCLUDE [Customer Name] : COUNTD([Order ID]) })
Example 2: % of Category Total
Goal: View shows Category + Sub-Category. For each Sub-Category, calculate what percentage its sales represent of the parent Category total.
{ EXCLUDE [Sub-Category] : SUM([Sales]) }
// Step 2: Calculate percentage
SUM([Sales]) / ATTR({ EXCLUDE [Sub-Category] : SUM([Sales]) })
Example 3: Deviation from Overall Average
Goal: View has Region + Sub-Category. Show how each mark's sales deviate from the overall average (across all Regions and Sub-Categories). We can EXCLUDE both dimensions.
{ EXCLUDE [Region], [Sub-Category] : AVG([Sales]) }
// Deviation
SUM([Sales]) - ATTR({ EXCLUDE [Region], [Sub-Category] : AVG([Sales]) })
Common Mistakes
Summary Reference
| Feature | INCLUDE | EXCLUDE | FIXED |
|---|---|---|---|
| Granularity change | Finer | Coarser | Independent |
| Dimension filters | Applied | Applied | Ignored |
| Context filters | Applied | Applied | Applied |
| Outer agg needed? | Yes (always) | Use \(\text{ATTR}()\) | Depends |
| View-dependent? | Yes | Yes | No |
Question 1 of 5
Your view has Region and State on Rows. You write:
{ EXCLUDE [State] : SUM([Sales]) }
What does this expression compute?
Question 2 of 5
You want to show the average order size per customer, but your view only has Segment on Rows. Which expression is correct?
Question 3 of 5
Which LOD keyword creates a calculation at a coarser granularity than the current view?
Question 4 of 5
You place an INCLUDE expression on Rows without wrapping it in an outer aggregation. What happens?
Question 5 of 5
Your view shows Category and Sub-Category. You write:
SUM([Sales]) / ATTR({ EXCLUDE [Sub-Category] : SUM([Sales]) })
What does this formula produce?