01 / 19

INCLUDE / EXCLUDE
LOD Expressions

Master Level of Detail calculations in Tableau to control granularity independently of your viz dimensions.

Tableau Data Analytics

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.

View Granularity
Sub-Category (fine grain): Chairs, Tables, Bookcases...
Desired Calculation
Category-level (coarser): Average Sales for all of "Furniture"

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.

FIXED
Computes at an exact set of dimensions you specify, ignoring the view entirely.
INCLUDE
Adds a dimension to the view granularity, making it finer.
EXCLUDE
Removes a dimension from the view granularity, making it coarser.

The INCLUDE Expression

// Syntax
{ 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

VIEW LEVEL Region East, West, Central, South + INCLUDE [Customer] INCLUDE LEVEL Region + Customer SUM(Sales) per combo Re-aggregate (AVG, MIN, MAX...) RESULT AVG per-customer sales shown at Region level Key Insight: INCLUDE goes finer, then comes back up to the view.

The EXCLUDE Expression

// Syntax
{ 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

VIEW LEVEL Region + Sub-Category Fine-grained marks - EXCLUDE [Sub-Category] EXCLUDE LEVEL Region only SUM(Sales) per Region Replicate value to every mark RESULT East: Chairs → $50K East: Tables → $50K (same Region total) Key Insight: EXCLUDE goes coarser, then duplicates back down.

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

1
Identify your view granularity. What dimensions are already on Rows, Columns, and Detail?
2
Determine the target granularity. Do you need finer detail (INCLUDE) or coarser aggregation (EXCLUDE)?
3
Pick the dimension to add or remove. This goes inside the curly braces after the keyword.
4
Choose your aggregation. SUM, AVG, MIN, MAX, or COUNTD after the colon.
5
Wrap the LOD in an outer aggregation when placing on a shelf (especially with INCLUDE).

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.

// Step 1: INCLUDE [Customer Name] to count orders per customer
{ 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.

// Step 1: Get Category-level total by EXCLUDING Sub-Category
{ 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.

// Overall average: exclude all view dimensions
{ EXCLUDE [Region], [Sub-Category] : AVG([Sales]) }

// Deviation
SUM([Sales]) - ATTR({ EXCLUDE [Region], [Sub-Category] : AVG([Sales]) })

Common Mistakes

✕ Forgetting the Outer Aggregation
INCLUDE returns a value per finer grain. When placed on a coarser shelf, Tableau needs you to wrap it in \(\text{AVG}()\), \(\text{SUM}()\), etc. Without it, you get an error.
✕ Using EXCLUDE on a Non-View Dimension
EXCLUDE can only remove dimensions already in the view. Excluding a dimension not on any shelf does nothing: the expression behaves like a regular aggregate.
✕ Confusing INCLUDE with FIXED
INCLUDE adds to the view; FIXED replaces the view. If you use FIXED when you mean INCLUDE, filters and dimension changes won't affect the calculation as expected.

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?