Tableau • Calculations and Metrics

INCLUDE/EXCLUDE LOD — Use INCLUDE/EXCLUDE LOD to control granularity

Master Level of Detail expressions to compute aggregations at precisely the granularity you need, independent of the view.

Tableau illustration with a dashboard presentation, data visualization, and database
Inside this lesson 10 sections 5 questions 9 figures

SECTION 1

Historical Context & Motivation

Before Tableau introduced Level of Detail (LOD) expressions in version 9.0, analysts faced a persistent problem: the granularity of every calculation was dictated solely by the dimensions present in the visualization. If your view displayed data at the product level, every aggregation—SUM, AVG, COUNT—was computed at the product level, with no straightforward way to reference a different grain. Workarounds existed—table calculations, data blending, custom SQL—but each introduced complexity, performance overhead, or fragility that made dashboard maintenance burdensome. For anyone accustomed to writing GROUP BY clauses in SQL, this limitation felt particularly constraining, because SQL lets you freely control the grouping level of any subquery or window function. LOD expressions were Tableau's answer to that gap, and the INCLUDE and EXCLUDE keywords gave analysts declarative control over which dimensions participate in an aggregation, independent of the view.

2003 • Tableau Founded

Tableau emerges from Stanford research on VizQL, a visual query language that translates drag-and-drop actions into database queries. Aggregation granularity is always coupled to the dimensions on the shelf.

2010 • Table Calculations Mature

Tableau 6 expands table calculations—WINDOW_SUM, RUNNING_TOTAL, LOOKUP—offering post-aggregation transformations. However, these operate on the result set, not the underlying data source, limiting their flexibility for cross-grain aggregation.

2015 • LOD Expressions Introduced (v9.0)

Tableau 9.0 introduces FIXED, INCLUDE, and EXCLUDE LOD expressions. For the first time, analysts can declaratively specify aggregation granularity at the data-source level, independent of the visualization's dimension shelf.

2018 • LOD + Sets & Parameters

Subsequent releases improve LOD expression compatibility with sets, parameters, and data source filters. Performance optimizations reduce the query overhead of nested LOD calculations.

2023 • Modern Analytics Ecosystem

LOD expressions are now foundational to advanced Tableau workflows, appearing in cohort analysis, customer segmentation, and KPI dashboards. They remain one of Tableau's most powerful—and most misunderstood—features.

The central question that INCLUDE and EXCLUDE LOD expressions address is deceptively simple: how do you compute a metric at a different level of granularity than what is currently displayed, and then seamlessly blend it back into the view? Understanding the answer requires a precise mental model of how Tableau's query pipeline processes dimensions, aggregations, and filters—and that is exactly what this lesson develops.

SECTION 2

Core Principles & Definitions

To wield INCLUDE and EXCLUDE LOD expressions effectively, you need to internalize a few foundational concepts about how Tableau constructs queries. Every visualization in Tableau implicitly defines a view-level granularity—the set of dimensions currently on the Rows, Columns, Color, Size, Detail, and Tooltip shelves. This view-level granularity determines the GROUP BY clause of the underlying query. LOD expressions let you override that implicit grouping by explicitly adding or removing dimensions from the aggregation context.

1

View-Level Granularity

The implicit grain of aggregation determined by dimensions on Tableau's shelves. Equivalent to the GROUP BY clause in the generated SQL. Every standard aggregation (SUM, AVG, etc.) operates at this level.
2

INCLUDE LOD

Adds one or more dimensions to the view-level grain, computing the aggregation at a finer level than the view. Syntax: { INCLUDE [Dim] : AGG(Measure) }. The result is then re-aggregated to the view level.
3

EXCLUDE LOD

Removes one or more dimensions from the view-level grain, computing the aggregation at a coarser level than the view. Syntax: { EXCLUDE [Dim] : AGG(Measure) }. The coarser value is then replicated across view rows.
4

FIXED LOD (Reference)

Defines an absolute grain, ignoring the view's dimensions entirely. Unlike INCLUDE/EXCLUDE, FIXED does not adapt when you add or remove dimensions from the view. It operates independently of the view-level context.
5

Re-Aggregation

When an INCLUDE LOD produces values at a finer grain than the view, Tableau must re-aggregate those values (e.g., AVG, MIN, MAX) to display them. This wrapping aggregation is key to understanding INCLUDE behavior.
✦

KEY TAKEAWAY

Think of the view's dimensions as a camera zoom level. INCLUDE is like zooming in—you see finer detail before aggregating back. EXCLUDE is like zooming out—you blur away a dimension to see a broader picture. In SQL terms, INCLUDE adds columns to GROUP BY; EXCLUDE removes columns from GROUP BY. Both are relative to the current view, which makes them adaptive as you evolve your dashboard.

SECTION 3

Visual Explanation

The following diagram illustrates how INCLUDE and EXCLUDE modify the aggregation grain relative to the view. The center column represents the view-level granularity—the dimensions currently on the shelves. INCLUDE shifts the computation to a finer grain (more dimensions), while EXCLUDE shifts it to a coarser grain (fewer dimensions). After the LOD calculation runs at its specified grain, the result is mapped back to the view through re-aggregation or replication.

INCLUDE vs EXCLUDE: Granularity ControlVIEW-LEVEL GRAIN[Region], [Category]INCLUDE [Product]GROUP BY Region,Category, ProductFiner grain → more rowsEXCLUDE [Category]GROUP BY RegionCoarser grain → fewer rows+ Dim− DimRe-AggregationAVG, MIN, MAX offiner-grain values→ back to view grainReplicationCoarser value iscopied to every rowat the view grainINCLUDE adds dimensions → finer grain → re-aggregate back. EXCLUDE removes dimensions → coarser grain → replicate values.
The view-level grain (center, purple border) represents the current dimensions on Tableau shelves. INCLUDE (left) adds a dimension, creating a finer aggregation that must be re-aggregated to display. EXCLUDE (right) removes a dimension, creating a coarser aggregation whose values are replicated across view rows.

Notice the critical distinction in the lower boxes. When INCLUDE computes at a finer grain, there are more intermediate rows than the view requires, so Tableau must wrap the LOD result in an outer aggregation—typically AVG(), MIN(), or MAX()—to collapse the extra rows back to the view level. Conversely, when EXCLUDE computes at a coarser grain, there are fewer intermediate rows, so the coarser result is simply replicated (broadcast) to each row at the view grain. This behavior directly parallels how SQL window functions replicate partition-level aggregates across row-level results.

SECTION 4

How INCLUDE and EXCLUDE Generate Queries

Understanding the SQL that Tableau generates from LOD expressions demystifies their behavior. Consider a view with [Region] and [Category] on the shelves. The view-level grain is GROUP BY Region, Category. An INCLUDE expression adds a dimension to that GROUP BY, while an EXCLUDE expression removes one. Tableau materializes the LOD computation as a subquery or common table expression (CTE) and then joins it back to the main query.

INCLUDE SYNTAX

INCLUDE[Dimension]:AGG([Measure]){ INCLUDE [Dimension] : AGG([Measure]) }

Effective grain = View dimensions ∪ {Dimension}. Tableau adds [Dimension] to the GROUP BY. The result is finer than the view, so an outer aggregation (e.g., AVG) is required when displayed.

EXCLUDE SYNTAX

EXCLUDE[Dimension]:AGG([Measure]){ EXCLUDE [Dimension] : AGG([Measure]) }

Effective grain = View dimensions \ {Dimension}. Tableau removes [Dimension] from the GROUP BY. The result is coarser than the view, so each coarser value is replicated across matching view rows.

Generated SQL Analogy

For a view with dimensions [Region] and [Category], an INCLUDE expression like { INCLUDE [Product] : SUM([Sales]) } generates a subquery equivalent to:

INCLUDE SQL EQUIVALENT

SELECTRegion,Category,Product,SUM(Sales)ASlodsalesFROMdataGROUPBYRegion,Category,ProductSELECT Region, Category, Product, SUM(Sales) AS lod_sales FROM data GROUP BY Region, Category, Product

This finer-grain result is then joined back to the main query. To display on the view (which groups by Region, Category only), Tableau wraps it: AVG(lod_sales) or whichever outer aggregation you specify.

EXCLUDE SQL EQUIVALENT

SELECTRegion,SUM(Sales)ASlodsalesFROMdataGROUPBYRegionSELECT Region, SUM(Sales) AS lod_sales FROM data GROUP BY Region

For { EXCLUDE [Category] : SUM([Sales]) }, Tableau removes [Category] from the GROUP BY. The coarser Region-level total is then replicated to every (Region, Category) row in the view—similar to a SQL window function SUM(Sales) OVER (PARTITION BY Region).

⚠

Filter Pipeline Note

INCLUDE and EXCLUDE LOD expressions are computed after dimension filters but before context filters (unless you promote a filter to context). This is different from FIXED LOD, which runs before dimension filters. This pipeline order is crucial for debugging unexpected results.

SECTION 5

Detailed Breakdown: When to Use INCLUDE vs EXCLUDE

Choosing between INCLUDE and EXCLUDE depends on whether you need to drill deeper than the view or pull back to a broader perspective. In practice, the choice often maps to a specific analytical pattern: INCLUDE is ideal when you need per-entity metrics before summarizing (e.g., average order size per customer, then averaged across regions), while EXCLUDE shines when you want each row to reference a parent-level total (e.g., category sales as a share of regional total). The following diagram maps common analytical scenarios to the appropriate LOD type.

Decision Flowchart: INCLUDE vs EXCLUDENeed a different grain?Is the desired grain relativeto the current view?No → Use FIXEDFIXED LODYesNeed finer or coarser grain?Finer (add dims)Coarser (remove dims)INCLUDEUse cases:• Avg order size per customer• Count of products per category• First purchase date per userWrap with AVG(), MIN(), MAX()EXCLUDEUse cases:• % of parent total• Difference from category avg• Regional benchmarkingValue is replicated across rows
Decision flowchart for selecting LOD type. If the desired grain is relative to the view and finer, use INCLUDE. If relative and coarser, use EXCLUDE. If the grain should be absolute (independent of the view), use FIXED.
ScenarioLOD TypeExpression ExampleOuter Aggregation
Average order value per customer, displayed per regionINCLUDE{ INCLUDE [Customer ID] : SUM([Sales]) }AVG(...)
Each sub-category's sales as a % of its category totalEXCLUDESUM([Sales]) / { EXCLUDE [Sub-Category] : SUM([Sales]) }Not needed (result is at view grain)
Count distinct products per category, view at region levelINCLUDE{ INCLUDE [Category] : COUNTD([Product]) }SUM(...)
Deviation of each month's sales from yearly averageEXCLUDESUM([Sales]) - { EXCLUDE [Month] : AVG([Sales]) }Not needed

Common analytical scenarios mapped to INCLUDE/EXCLUDE LOD patterns

SECTION 6

Worked Example: Customer-Level Metrics in a Regional View

Suppose you have a Superstore-style dataset and a bar chart showing SUM([Sales]) per [Region]. Your goal is two-fold: (1) compute the average sales per customer in each region using INCLUDE, and (2) compute the percentage of total sales each region represents using EXCLUDE.

Part A — INCLUDE: Average Sales per Customer by Region

  1. 1

    Step 1 — Identify the View Grain

    The view has [Region] on Rows and SUM([Sales]) on Columns. The view grain is Region alone.
  2. 2

    Step 2 — Define the INCLUDE LOD Expression

    We want per-customer sales, which is finer than per-region. We create a calculated field: { INCLUDE [Customer ID] : SUM([Sales]) }. This tells Tableau to compute SUM(Sales) grouped by Region, Customer ID (the view dims plus the included dim).
    Effective grain: GROUP BY Region, Customer ID
  3. 3

    Step 3 — Apply the Outer Aggregation

    Since the LOD result has one row per (Region, Customer ID) but the view only shows one row per Region, we must re-aggregate. Drag the LOD field to the view and select AVG as the aggregation. The pill reads AVG({ INCLUDE [Customer ID] : SUM([Sales]) }).
    East: $1,245 avg per customer · West: $1,098 · Central: $967 · South: $1,102 (illustrative values)
  4. 4

    Step 4 — Interpret

    The result tells us the average total spending per customer within each region—a metric that would be impossible to compute with a simple AVG([Sales]) (which averages across individual rows/transactions, not customers). The INCLUDE keyword injected the per-customer grain, and the outer AVG collapsed it to the per-region view.

Part B — EXCLUDE: Percentage of Total Sales per Region

  1. 1

    Step 1 — Identify What to Exclude

    To compute the overall total sales (ignoring Region), we exclude the only view dimension: { EXCLUDE [Region] : SUM([Sales]) }. With Region removed, the effective grain is the entire dataset—one grand total.
    Effective grain: entire table (no GROUP BY)
  2. 2

    Step 2 — Build the Percentage Calculation

    Create a calculated field: SUM([Sales]) / { EXCLUDE [Region] : SUM([Sales]) }. The numerator is the region-level total (view grain), and the denominator is the grand total (coarser grain, replicated to each region row).
  3. 3

    Step 3 — Format and Verify

    Format the result as a percentage. Each region now shows its share of total sales. Because the EXCLUDE expression adapts to the view, if you later add [Category] to the view, the denominator automatically becomes the total excluding Region but including Category—exactly what you'd want for a per-category share.
    East: 29.5% · West: 31.6% · Central: 21.8% · South: 17.1% (illustrative)

SECTION 7

Strengths, Limitations & Comparisons

CharacteristicINCLUDE LODEXCLUDE LODFIXED LOD
Grain relative to viewFiner (adds dimensions)Coarser (removes dimensions)Independent (absolute)
AdaptabilityAdapts when view dims changeAdapts when view dims changeDoes NOT adapt
Filter pipeline positionAfter dimension filtersAfter dimension filtersBefore dimension filters
Requires outer aggregationYes (AVG, MIN, MAX, etc.)No (value replicated; aggregation is ATTR-like)Depends on context
PerformanceCan be expensive with high-cardinality dimsGenerally efficient (fewer groups)Varies; often most efficient for simple cases
Typical use casePer-entity metrics rolled up to the viewPercent-of-parent, benchmarks, deviationsCohort assignment, date-based bucketing

Comparison of INCLUDE, EXCLUDE, and FIXED LOD expressions

Strengths of INCLUDE/EXCLUDE

  • ✓ View-adaptive: Both INCLUDE and EXCLUDE automatically adjust their effective grain when you add or remove dimensions from the view. This makes dashboards more maintainable than FIXED-based approaches for view-relative calculations.
  • ✓ Filter-respecting: Because they sit after dimension filters in the pipeline, INCLUDE and EXCLUDE respect the user's filter selections—a behavior that analysts usually expect.
  • ✓ Composable: You can nest LOD expressions inside other calculations, use them in IF statements, or combine INCLUDE and EXCLUDE results in a single formula.

Limitations and Pitfalls

  • Outer aggregation confusion: INCLUDE results must be wrapped in an outer aggregation. Forgetting this—or using the wrong one—is the most common source of errors. AVG, MIN, and MAX produce very different results.
  • Performance with high cardinality: INCLUDE on a high-cardinality dimension (e.g., Customer ID with millions of distinct values) forces Tableau to compute a much larger intermediate result set, which can degrade query performance.
  • EXCLUDE on the last dimension: If you EXCLUDE the only dimension in the view, the grain becomes the entire dataset. This is valid but can be confusing to interpret.
✦

KEY TAKEAWAY

Think of INCLUDE and EXCLUDE like SQL's GROUP BY modifications scoped to a single calculated field. INCLUDE is analogous to a correlated subquery that joins on all view dimensions plus extra ones; EXCLUDE is analogous to a PARTITION BY in a window function where you've deliberately omitted a column. The key advantage over FIXED is adaptability: as the dashboard evolves, these expressions evolve with it.

SECTION 8

Connection to Advanced LOD Patterns

INCLUDE and EXCLUDE LOD expressions form the foundation for several advanced analytical patterns in Tableau. Once you have mastered the basic mechanics, you can compose these expressions to handle complex, multi-grain calculations that would otherwise require custom SQL or data model changes. The following table contrasts basic usage with advanced patterns that build on the same principles.

Basic PatternAdvanced ExtensionDescription
{ INCLUDE [Cust] : SUM(Sales) }Nested LOD: INCLUDE inside FIXEDCompute per-customer sales first, then fix at a cohort level. E.g., { FIXED [Cohort] : AVG({ INCLUDE [Cust] : SUM(Sales) }) }
{ EXCLUDE [Month] : SUM(Sales) }Year-over-year difference with EXCLUDEExclude the month dimension to get an annual total, then compute each month's deviation from the yearly average—a dynamic variance analysis.
Simple percent-of-totalMulti-level percent-of-parentChain EXCLUDE expressions at different levels: exclude Sub-Category for category share, exclude Category for segment share. Each provides a different hierarchical benchmark.
Customer order count (INCLUDE)Frequency binningUse INCLUDE to compute order frequency per customer, then bin the result into "1 order", "2–5 orders", "6+ orders" groups for a histogram at the view level.

Basic vs. advanced LOD patterns

As you move toward more sophisticated Tableau development—building parameter-driven dashboards, implementing row-level security, or designing reusable calculated fields—the ability to reason about grain management becomes indispensable. LOD expressions are, at their core, a way to declaratively manage grain in a visual analytics environment. This concept maps directly to dimensional modeling principles (Kimball methodology), where fact tables exist at specific grains and bridge tables mediate between grains. If you continue into data engineering or analytics engineering (e.g., dbt, LookML), you will encounter the same grain-management challenges at the modeling layer, and the mental model you build here transfers directly.

💡

Looking Ahead

Tableau's newer features—Relationships (introduced in 2020.2) and multi-fact data models—interact with LOD expressions in nuanced ways. When working with relationships, LOD calculations respect the level of detail defined by the relationship's join type, which can produce unexpected results if you're not deliberate about which tables contribute to the grain. Mastering INCLUDE/EXCLUDE now provides the conceptual foundation for navigating these newer paradigms.

SECTION 9

Practice Problems

Question 1: CONCEPTUAL

Explain in your own words why an INCLUDE LOD expression requires an outer aggregation (e.g., AVG, MAX) when displayed in a view, while an EXCLUDE LOD expression does not. Reference the concept of grain mismatch in your answer.
Show answer
An INCLUDE expression computes at a grain that is finer than the view—there are more rows in the LOD result than in the view. To collapse these extra rows into the view-level grain, Tableau must apply a re-aggregation function (AVG, MIN, MAX, etc.). In contrast, an EXCLUDE expression computes at a grain coarser than the view—there are fewer rows. Each coarser-level value is simply replicated (broadcast) to all matching view rows. Since the value is identical for every view row within its group, no further aggregation is needed; Tableau effectively uses ATTR() semantics, which returns the single replicated value.

Question 2: BASIC CALCULATION

You have a view showing [Category] on Rows and SUM([Profit]) on Columns. Write an INCLUDE LOD expression that computes the total profit per customer within each category, and then the correct pill expression to display the average of those customer-level profits.
Show answer
First, create a calculated field named 'Customer Profit': { INCLUDE [Customer ID] : SUM([Profit]) }. This calculates SUM(Profit) grouped by Category and Customer ID (the view dim plus the included dim). To display the average customer profit per category, drag this field to the view and set its aggregation to AVG. The pill reads: AVG({ INCLUDE [Customer ID] : SUM([Profit]) }). This gives you the mean profit per customer within each category—a metric that reveals customer-level profitability patterns that the simple SUM would obscure.

Question 3: INTERMEDIATE

Your view shows [Region] and [Sub-Category] on Rows with SUM([Sales]) on Columns. Write an EXCLUDE LOD expression to compute each sub-category's sales as a percentage of its region's total sales. Then explain what happens to the denominator if you remove [Region] from the view.
Show answer
The expression is: SUM([Sales]) / { EXCLUDE [Sub-Category] : SUM([Sales]) }. The EXCLUDE removes [Sub-Category] from the view grain, leaving just [Region], so the denominator becomes the total sales per region. Each (Region, Sub-Category) row divides its sales by the corresponding region total. If you then remove [Region] from the view, the view grain becomes just [Sub-Category]. The EXCLUDE expression now removes [Sub-Category] from that single-dimension grain, leaving no grouping dimensions—meaning the denominator becomes the grand total across all data. The expression seamlessly transitions from 'percent of region' to 'percent of grand total.' This adaptive behavior is the defining advantage of EXCLUDE over FIXED.

Question 4: APPLIED

A product manager asks you to build a dashboard that shows average order size per customer by region, but also flags any region where the average order size is more than 20% below the overall company average. Using INCLUDE and EXCLUDE LOD expressions, describe the calculated fields you would create and how you would implement the flag.
Show answer
First, compute per-customer order sizes using INCLUDE: [Customer Order Size] = { INCLUDE [Customer ID] : SUM([Sales]) / COUNTD([Order ID]) }. Display it as AVG([Customer Order Size]) on the view (grouped by Region). Next, compute the company-wide benchmark using EXCLUDE: [Company Avg Order Size] = { EXCLUDE [Region] : AVG({ INCLUDE [Customer ID] : SUM([Sales]) / COUNTD([Order ID]) }) }. This nested expression first computes per-customer order size, then averages it across all customers regardless of region. Finally, create the flag: [Below Threshold] = AVG([Customer Order Size]) < 0.8 × ATTR([Company Avg Order Size]). Place this on the Color shelf to highlight underperforming regions. The nesting of INCLUDE inside EXCLUDE demonstrates how composable LOD expressions handle multi-grain requirements in a single dashboard.

Question 5: CRITICAL THINKING

Consider the filter pipeline: Data Source Filters → Context Filters → FIXED LOD → Dimension Filters → INCLUDE/EXCLUDE LOD → Measure Filters → Table Calculations. A colleague has built a dashboard using { EXCLUDE [State] : SUM([Sales]) } to show each state's sales as a share of regional total. However, when the user selects specific states in a dimension filter, the denominator (regional total) shrinks to only include the filtered states, distorting the percentages. Propose and justify a solution using either context filters or a different LOD type, and analyze the trade-offs of each approach.
Show answer
The root cause is that INCLUDE/EXCLUDE LOD expressions execute after dimension filters, so the EXCLUDE denominator only sees filtered states. Two solutions exist: (1) Promote the state filter to a Context Filter. Context filters execute before FIXED LOD but also before INCLUDE/EXCLUDE, which means they will still affect the EXCLUDE denominator—so this approach alone does NOT solve the problem for EXCLUDE. (2) Replace the EXCLUDE with a FIXED expression: { FIXED [Region] : SUM([Sales]) }. FIXED runs before dimension filters, so the denominator reflects all states regardless of the dimension filter selection. The trade-off: FIXED is not view-adaptive. If you later add or remove dimensions from the view, the FIXED denominator remains locked to [Region], whereas the EXCLUDE approach would have adapted. Additionally, FIXED ignores dimension filters for ALL users, which might not be desirable if some filters represent legitimate data access restrictions. A nuanced approach combines both: use FIXED for the denominator but add the state filter to context when you want it to apply globally. Understanding where each LOD type sits in the filter pipeline is essential for predictable behavior.

SUMMARY

Lesson Summary

Summary

INCLUDE LOD expressions add dimensions to the view-level granularity, computing aggregations at a finer grain. The result must be wrapped in an outer aggregation (AVG, MIN, MAX) to collapse back to the view level. EXCLUDE LOD expressions remove dimensions, computing at a coarser grain and replicating the result to view rows. Both are view-adaptive—they automatically adjust when you modify the dimensions on the shelves—and both execute after dimension filters in Tableau's filter pipeline.

The choice between INCLUDE and EXCLUDE maps to a clear decision: if you need to drill to a finer grain (e.g., per-customer metrics before regional rollup), use INCLUDE. If you need to reference a coarser grain (e.g., percent-of-parent, deviation from group average), use EXCLUDE. For absolute grain control independent of the view, use FIXED. These three LOD keywords, combined with Tableau's filter pipeline, give you precise, declarative control over aggregation granularity—a capability that parallels SQL's GROUP BY and window functions but within a visual interface.

Varsity Tutors • Tableau • INCLUDE/EXCLUDE LOD — Use INCLUDE/EXCLUDE LOD to control granularity