Popular Searches
Popular Course Categories
Popular Courses

LOD Expressions and Aggregations

LOD Expressions and Aggregations

Level of Detail (LOD) Expressions

LOD Expressions and Aggregations in Tableau

Topic: Level of Detail (LOD) Expressions and Aggregation Functions

Objective: Understand how Tableau calculates aggregated values at different levels of detail, how LOD expressions interact with dimensions in a visualization, and how to use them for accurate business analysis.

Course: JustAcademy Tableau Training

Course Demo: Register for a Tableau Course Demo


1. Introduction to LOD Expressions

LOD stands for Level of Detail. In Tableau, LOD expressions allow you to specify the level at which a calculation should be performed, independently of or in combination with the dimensions displayed in a visualization.

For example, a chart may display sales by region and category, but you may also need to calculate total sales for each customer, average sales for each region, or total sales across the entire dataset. LOD expressions help perform these calculations at the required granularity.

Why Are LOD Expressions Important?

  • Calculate metrics at a specific level of detail.
  • Compare detailed values with overall totals or averages.
  • Calculate customer-level, product-level, order-level, and regional metrics.
  • Support percentage-of-total and performance comparisons.
  • Reduce errors caused by calculating values at the wrong level of granularity.
  • Combine calculations at different levels in the same visualization.

Example

Suppose your dataset contains sales records for multiple products and customers. Your visualization displays sales by region, but you want to calculate total sales per customer regardless of the current chart structure.

{FIXED [Customer Name] : SUM([Sales])}

This expression calculates the total sales for each customer. The result can then be used in a visualization that displays other dimensions, such as region or category.


2. Understanding Aggregation in Tableau

Aggregation means combining multiple data values into a summarized result. Tableau commonly aggregates measures when you place them in a visualization.

For example, a dataset might contain hundreds of sales transactions. Instead of displaying every transaction, Tableau can summarize the transactions into total sales for each region.

Common Aggregation Functions

Function Purpose Example
SUM() Adds numeric values. SUM([Sales])
AVG() Calculates the arithmetic mean. AVG([Sales])
MIN() Returns the smallest value. MIN([Sales])
MAX() Returns the largest value. MAX([Sales])
COUNT() Counts non-null values. COUNT([Order ID])
COUNTD() Counts distinct, non-null values. COUNTD([Customer ID])
MEDIAN() Returns the median of numeric values. MEDIAN([Sales])
ATTR() Displays a value when the underlying values are consistent; otherwise, it may display an asterisk. ATTR([Region])

Example Dataset

Order ID Region Product Sales
101 East Laptop 1000
102 East Mouse 200
103 West Laptop 1500
104 West Keyboard 300
105 East Monitor 800

Aggregation Results

  • Total Sales: 1000 + 200 + 1500 + 300 + 800 = 3800.
  • Average Sales: 3800 / 5 = 760.
  • Minimum Sales: 200.
  • Maximum Sales: 1500.
  • Number of Orders: 5, when each row represents one order.

These results can change if the dataset contains null values, duplicate records, or multiple transaction rows per order. Always understand the grain of your data before choosing an aggregation.


3. What Is Granularity?

Granularity describes the level of detail represented by a record or a calculation.

For example, a dataset can contain one row per transaction, while a chart summarizes the data by region. The source data is at transaction-level granularity, but the visualization is at region-level granularity.

Level Example
Transaction level Sales for each individual transaction.
Order level Total sales for each order.
Customer level Total sales for each customer.
Product level Total sales for each product.
Region level Total sales for each region.
Dataset level Total sales for the entire dataset.

LOD expressions are useful when the desired calculation granularity differs from the granularity of the visualization.


4. Standard Aggregations vs. LOD Expressions

Standard aggregations usually summarize records at the level determined by the dimensions in the view. LOD expressions let you explicitly define a different calculation level.

Feature Standard Aggregation LOD Expression
Calculation level Usually follows the dimensions in the view. Can specify or modify calculation granularity.
Example SUM([Sales]) {FIXED [Region] : SUM([Sales])}
View changes Results often change when dimensions are added or removed. Behavior depends on whether FIXED, INCLUDE, or EXCLUDE is used.
Typical use Summarizing sales in a chart. Comparing regional totals with category-level or customer-level results.
Complex analysis May require several separate calculations. Can calculate metrics at different levels in one analysis.

Example

Standard aggregation:

SUM([Sales])

This summarizes sales according to the dimensions in the view.

LOD expression:

{FIXED [Region] : SUM([Sales])}

This calculates sales at region level regardless of other dimensions in the view. If the view includes both Region and Product, the regional total may repeat for each product within that region.


5. Types of LOD Expressions

Tableau supports three principal types of LOD expressions: FIXED, INCLUDE, and EXCLUDE. Each controls granularity differently.

Type Meaning Typical Use
FIXED Calculates using the dimensions explicitly specified in the expression. Regional totals, customer totals, first purchase date.
INCLUDE Adds specified dimensions to the dimensions already in the view. Average customer sales by region.
EXCLUDE Removes specified dimensions from the view's level of detail for the calculation. Comparing category sales with total sales across categories.
Table-scoped LOD Calculates an aggregate across the table without a FIXED, INCLUDE, or EXCLUDE keyword. Minimum date or total value for the dataset.

6. FIXED LOD Expressions

A FIXED expression calculates a value using only the dimensions declared in the expression. It does not use the dimensions in the visualization to determine its calculation granularity.

Syntax

{FIXED [Dimension] : AGGREGATION([Measure])}

Example 1: Sales by Region

{FIXED [Region] : SUM([Sales])}

This expression calculates total sales for each region.

Example 2: Sales by Customer

{FIXED [Customer Name] : SUM([Sales])}

This calculates total sales for each customer. It can be used to identify high-value customers or compare customer performance.

Example 3: Total Sales for the Entire Dataset

{FIXED : SUM([Sales])}

Because no dimension is specified, this calculates total sales for the entire data domain that reaches the FIXED calculation, subject to the relevant data-source, extract, and context filters.

Example 4: Sales by Region and Category

{FIXED [Region], [Category] : SUM([Sales])}

This calculates sales for each unique combination of region and category.

Important Point

FIXED expressions are evaluated before ordinary dimension filters, but after extract, data-source, and context filters in Tableau's filter order. If a dimension filter must affect a FIXED calculation, consider adding that filter to context when appropriate.


7. INCLUDE LOD Expressions

An INCLUDE expression adds one or more dimensions to the dimensions already present in the view when performing the calculation.

Syntax

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

Example 1: Customer Sales Within a Region

{INCLUDE [Customer Name] : SUM([Sales])}

Suppose Region is displayed in the chart. INCLUDE Customer Name calculates sales at customer-level detail within the view's dimensional context. If the resulting measure is aggregated as AVG, the chart can show average customer sales for each region.

Example 2: Average Sales per Order

{INCLUDE [Order ID] : SUM([Sales])}

This first calculates sales for each order. If the resulting field is then averaged, it can be used to calculate average order value. Ensure the data model and order identifiers correctly represent the intended order grain.

When to Use INCLUDE

  • When a calculation requires a finer level of detail than the current view.
  • When you need to aggregate detailed results back to a higher level.
  • When comparing average customer sales across regions.
  • When calculating a statistic over order-level totals instead of individual transaction rows.

8. EXCLUDE LOD Expressions

An EXCLUDE expression removes one or more dimensions from the view's level of detail for the calculation.

Syntax

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

Example: Total Sales Across Regions for Each Month

{EXCLUDE [Region] : SUM([Sales])}

If a visualization displays Month and Region, this expression calculates sales at the view's level of detail with Region removed. The resulting monthly total can be repeated across the regional marks for that month.

Example: Average Sales Without Product Detail

{EXCLUDE [Product Name] : AVG([Sales])}

This excludes Product Name from the view's level of detail when evaluating the expression. The result depends on the other dimensions remaining in the view.

When to Use EXCLUDE

  • Compare individual category values with a total that excludes category detail.
  • Compare monthly sales with a broader average.
  • Create calculations that remove a dimension from the current view context.
  • Support percentage-of-total and difference-from-total analyses.

9. Table-Scoped LOD Expressions

A table-scoped LOD expression contains an aggregate calculation inside curly brackets without a FIXED, INCLUDE, or EXCLUDE keyword.

Syntax and Examples

{MIN([Order Date])}
{MAX([Order Date])}
{SUM([Sales])}

For example, {MIN([Order Date])} calculates the earliest order date for the relevant table-level data domain. Table-scoped LOD expressions are useful for dataset-level aggregate calculations.

A table-scoped expression such as {MIN([Order Date])} is equivalent in scope to {FIXED : MIN([Order Date])}.


10. Aggregation Inside LOD Expressions

An LOD expression normally includes an aggregate expression after the colon. The aggregation function determines what is calculated at the specified level of detail.

Examples

{FIXED [Region] : SUM([Sales])}
{FIXED [Region] : AVG([Profit])}
{FIXED [Product Name] : MIN([Sales])}
{FIXED [Product Name] : MAX([Sales])}
{FIXED [Customer Name] : COUNT([Order ID])}
{FIXED [Customer Name] : COUNTD([Order ID])}
Expression Interpretation
{FIXED [Region] : SUM([Sales])} Total sales per region.
{FIXED [Region] : AVG([Profit])} Average profit at region level, based on the underlying records.
{FIXED [Product Name] : MIN([Sales])} Minimum sales value per product.
{FIXED [Product Name] : MAX([Sales])} Maximum sales value per product.
{FIXED [Customer Name] : COUNT([Order ID])} Count of non-null Order ID values per customer.
{FIXED [Customer Name] : COUNTD([Order ID])} Count of distinct, non-null orders per customer.

Important: COUNT([Order ID]) counts non-null records, not necessarily distinct orders. If each order has multiple rows, COUNTD([Order ID]) may be more appropriate for counting unique orders.


11. Understanding Nested Aggregations and LOD Expressions

Nested LOD expressions use one LOD expression inside another calculation. They are useful when one calculation needs to establish a detailed metric and another needs to summarize that metric at a different level.

Example: Monthly Sales Total

{FIXED [Month] : SUM([Sales])}

This calculates the total sales for each month. Use the actual date field or a consistent month-level date dimension in the calculation.

Example: Compare Monthly Sales with Average Monthly Sales

First, create a calculated field named Monthly Sales:

{FIXED [Month] : SUM([Sales])}

Next, create a calculated field named Average Monthly Sales:

{EXCLUDE [Month] : AVG({FIXED [Month] : SUM([Sales])})}

Then calculate the difference:

[Monthly Sales] - [Average Monthly Sales]

The resulting value indicates how much monthly sales are above or below the average monthly total. For a reliable result, use a consistent month dimension and ensure the view's dimensions match the intended analysis.


12. Aggregation and View Granularity

When an LOD result is placed in a visualization, Tableau reconciles the granularity of the LOD expression with the granularity of the view. The result may be aggregated, repeated across marks, or appear at the same level as the view.

Case 1: LOD Is Coarser Than the View

A calculation is coarser when it uses fewer dimensions than the view.

Example view: Region and Product.

{FIXED [Region] : SUM([Sales])}

The calculation is at region level, while the view is at region-and-product level. The regional total can therefore repeat for each product in the region.

Case 2: LOD Is Finer Than the View

A calculation is finer when it uses more dimensions than the view.

Example view: Region.

{FIXED [Region], [Customer Name] : SUM([Sales])}

The calculation produces values for region-customer combinations. If the view displays only Region, Tableau must aggregate those detailed results to the regional level.

Case 3: LOD and View Have the Same Granularity

If the dimensions in the LOD expression match the view's relevant dimensions, the result may align directly with the marks in the visualization.

Relationship Example Typical Result
LOD coarser than view Region LOD in a Region + Product view Regional values can repeat across products.
LOD finer than view Region + Customer LOD in a Region view Detailed values must be aggregated to region level.
Same granularity Region LOD in a Region view Values generally align with regional marks.

INCLUDE expressions use the view dimensions plus the specified dimensions and therefore do not create repeated values merely because the LOD is coarser than the view. FIXED can be coarser, finer, or equal to the view. EXCLUDE removes dimensions from the view's calculation context and commonly produces repeated values across the excluded dimension.


13. LOD Expressions and Filter Order

Filters affect LOD calculations differently depending on the type of LOD expression. Understanding filter order is essential when totals appear not to match the visible marks.

General Filter Order in Tableau

  1. Extract filters.
  2. Data source filters.
  3. Context filters.
  4. FIXED LOD calculations are evaluated before ordinary dimension filters.
  5. Dimension filters.
  6. INCLUDE and EXCLUDE LOD calculations are evaluated after dimension filters.
  7. Measure filters.
  8. Table calculation filters.

This is a simplified guide to the relevant order; the full Tableau order of operations includes additional stages.

Example

Consider the expression:

{FIXED : SUM([Sales])}

If you filter Region to show only East using an ordinary dimension filter, the FIXED total can still include sales from all regions because the calculation occurs before that filter.

If you need the FIXED calculation to respect the selected Region filter, consider adding the filter to context. INCLUDE and EXCLUDE calculations are evaluated after dimension filters, so their results can respond differently.


14. Calculating Percentage of Total with LOD

Percentage of total compares a category's sales with a broader total. A FIXED expression can calculate the total sales denominator, while the numerator calculates sales at the current view's level.

Formula

SUM([Sales]) / ATTR({FIXED : SUM([Sales])})

Format the result as a percentage. The denominator represents total sales in the FIXED calculation's data domain, which may include regions hidden by ordinary dimension filters.

Example

Region Sales Share of Total
East 1900 50%
West 1800 47.37%
Central 100 2.63%
Total 3800 100%

For East, the percentage is 1900 / 3800 × 100 = 50%. The sample values illustrate the arithmetic; your actual results depend on the dataset and filter context.


15. LOD Expressions for Business Analysis

Customer Lifetime Sales

{FIXED [Customer ID] : SUM([Sales])}

Use this to estimate total recorded sales for each customer within the data domain included in the calculation.

Average Order Value

First calculate total sales for each order:

{FIXED [Order ID] : SUM([Sales])}

Then aggregate the order-level result using AVG in the view to calculate average order value. Confirm that each Order ID correctly represents one order in your dataset.

First Purchase Date per Customer

{FIXED [Customer ID] : MIN([Order Date])}

This returns the earliest order date for each customer in the data domain included in the calculation. It can support customer cohort and retention analysis.

Distinct Customers per Region

{FIXED [Region] : COUNTD([Customer ID])}

This calculates the number of distinct customers associated with each region.

Maximum Sales per Product

{FIXED [Product Name] : MAX([Sales])}

This returns the largest sales value among the underlying records for each product. It does not necessarily represent the product's total sales.


16. Step-by-Step Practical Exercise

Project: Analyze regional sales and customer performance using LOD expressions.

Step 1: Connect to Data

  1. Open Tableau Desktop or another Tableau authoring environment.
  2. Connect to a dataset containing fields such as Region, Customer Name, Order ID, Order Date, Sales, and Profit.
  3. Open a new worksheet.

Step 2: Create Regional Sales

  1. Open the Data pane.
  2. Select Create Calculated Field.
  3. Name the field Regional Sales.
  4. Enter the calculation:
{FIXED [Region] : SUM([Sales])}

Step 3: Create Customer Sales

{FIXED [Customer Name] : SUM([Sales])}

Name the calculated field Customer Sales.

Step 4: Create Distinct Orders per Customer

{FIXED [Customer Name] : COUNTD([Order ID])}

Name the field Distinct Orders per Customer.

Step 5: Create Average Sales per Customer

For a region-level view, create an INCLUDE calculation:

{INCLUDE [Customer Name] : SUM([Sales])}

Add Region to the view and use AVG on this calculated field to examine average customer sales within each region. Validate the behavior against your data structure.

Step 6: Create a Regional Comparison

Place Region on Rows and SUM(Sales) on Columns. Add Regional Sales to Label or Tooltip. If the regional LOD total repeats across other dimensions, remember that it represents the regional total rather than a product-level total.

Step 7: Test Filter Behavior

  1. Add Region to Filters.
  2. Filter to one region.
  3. Compare the standard sales result with the FIXED total.
  4. Convert the Region filter to a context filter and observe the change where applicable.

Step 8: Build the Dashboard

Create a dashboard containing regional sales, average customer sales, distinct order counts, and a customer sales ranking. Add clear titles, readable number formats, and useful tooltips.


17. Common Mistakes and Troubleshooting

Mistake Why It Happens How to Fix It
Using SUM when AVG is required The result summarizes values differently from the business question. Confirm whether the requirement is total, average, minimum, maximum, or distinct count.
Assuming FIXED responds to every filter FIXED is evaluated before ordinary dimension filters. Check the filter order and use context filters where appropriate.
Repeated totals in a chart The LOD calculation is coarser than the view. Check the dimensions in the LOD expression and the visualization.
Unexpected results after adding a dimension INCLUDE and EXCLUDE respond to the dimensions in the view. Review the expression's granularity and test with a simple table.
Counting duplicate orders COUNT counts non-null records, which may include repeated Order IDs. Use COUNTD when distinct orders are required.
Mixing aggregate and row-level values The calculation combines fields at incompatible levels. Use an appropriate aggregation or an LOD expression to align the calculation levels.
Using a table calculation inside an LOD aggregate expression Table calculations are not permitted inside the aggregate expression of an LOD. Separate the LOD and table calculation into appropriate calculation stages.
Unexpected percentages The numerator and denominator use different data domains or filter contexts. Check filter order, denominator scope, and the intended definition of total.

18. Best Practices for LOD Expressions

  • Understand the granularity of the source data before writing calculations.
  • Choose FIXED when you need an explicitly defined dimensional level independent of the view.
  • Choose INCLUDE when you need additional detail beyond the dimensions in the view.
  • Choose EXCLUDE when you need to remove a dimension from the view's calculation context.
  • Use meaningful calculated-field names, such as Customer Sales or Regional Sales.
  • Test calculations in a simple text table before placing them in a complex dashboard.
  • Verify the effect of dimension filters and context filters.
  • Use COUNTD rather than COUNT when unique entities are required and identifiers may repeat.
  • Format percentages, currency, dates, and decimal places consistently.
  • Validate calculations against a manual calculation or a trusted summary.
  • Avoid unnecessary nested LOD expressions when a simpler calculation produces the intended result.

19. Practice Exercises

  1. Create an LOD expression to calculate total sales for each region.
  2. Create an LOD expression to calculate average profit for each category.
  3. Calculate total sales for each customer.
  4. Find the earliest order date for each customer.
  5. Count distinct orders for each region.
  6. Calculate sales for each customer and use AVG to compare average customer sales across regions.
  7. Create a regional total using FIXED and test what happens when Product Name is added to the view.
  8. Create an EXCLUDE expression that removes Category from a view displaying Region and Category.
  9. Calculate each region's share of overall sales.
  10. Filter the view to one region and compare the behavior of a FIXED total with a context filter and an ordinary dimension filter.

Sample Answers

1. {FIXED [Region] : SUM([Sales])}
2. {FIXED [Category] : AVG([Profit])}
3. {FIXED [Customer Name] : SUM([Sales])}
4. {FIXED [Customer ID] : MIN([Order Date])}
5. {FIXED [Region] : COUNTD([Order ID])}
6. {INCLUDE [Customer Name] : SUM([Sales])}
7. {FIXED [Region] : SUM([Sales])}
8. {EXCLUDE [Category] : SUM([Sales])}
9. SUM([Sales]) / ATTR({FIXED : SUM([Sales])})
10. Compare the FIXED result before and after converting the filter to context.

Note: For exercise 6, use AVG on the INCLUDE calculated field in the view to obtain average customer-level sales. For exercise 8, the result depends on the remaining dimensions in the view. Format exercise 9 as a percentage and validate its denominator against the intended filter scope.


20. Interview Questions and Answers

Q1. What is an LOD expression in Tableau?

Answer: An LOD expression lets you control the level of detail at which a calculation is performed, independently of or in combination with the dimensions in the view.

Q2. What are the three main types of LOD expressions?

Answer: FIXED, INCLUDE, and EXCLUDE.

Q3. What is the difference between FIXED and INCLUDE?

Answer: FIXED calculates using the dimensions explicitly declared in the expression, while INCLUDE adds the specified dimensions to the dimensions already present in the view.

Q4. What is the difference between INCLUDE and EXCLUDE?

Answer: INCLUDE adds dimensions to the view's level of detail for the calculation, whereas EXCLUDE removes specified dimensions from the view's level of detail for the calculation.

Q5. What is aggregation in Tableau?

Answer: Aggregation summarizes multiple data values using functions such as SUM, AVG, MIN, MAX, COUNT, and COUNTD.

Q6. Why might an LOD value repeat across multiple rows in a visualization?

Answer: The LOD calculation may be at a coarser level than the view. For example, a regional total can repeat across every product displayed within that region.

Q7. How do FIXED expressions respond to dimension filters?

Answer: FIXED expressions are evaluated before ordinary dimension filters, so those filters do not generally affect the FIXED result. Context filters, data-source filters, and extract filters can affect it.

Q8. When should COUNTD be used?

Answer: Use COUNTD when the requirement is to count unique, non-null values, such as distinct customers or distinct orders.

Q9. Can LOD expressions be nested?

Answer: Yes. Nested LOD expressions can calculate a metric at one level and use it within a calculation at another level, subject to Tableau's calculation rules.

Q10. What is a table-scoped LOD expression?

Answer: It is an LOD expression that contains an aggregate calculation inside curly brackets without a FIXED, INCLUDE, or EXCLUDE keyword, such as {MIN([Order Date])}.

Q11. How can you calculate sales by region regardless of other view dimensions?

Answer: Use {FIXED [Region] : SUM([Sales])}.

Q12. How do you calculate average order value with an LOD expression?

Answer: Calculate sales at order level using {FIXED [Order ID] : SUM([Sales])}, then average those order-level results in the view.


21. Quick Revision Checklist

  • Understand the difference between aggregation and granularity.
  • Know the purpose of SUM, AVG, MIN, MAX, COUNT, and COUNTD.
  • Remember the syntax of FIXED, INCLUDE, and EXCLUDE.
  • Know when an LOD expression can repeat values across marks.
  • Understand how LOD granularity interacts with view granularity.
  • Understand how FIXED differs from INCLUDE and EXCLUDE in filter order.
  • Know how to calculate customer sales, regional sales, average order value, and first purchase date.
  • Validate calculations against the intended business definition.

22. Conclusion

LOD expressions and aggregation functions are essential Tableau concepts for building reliable, flexible data analysis. Aggregation functions summarize values, while LOD expressions control the level at which those summaries are calculated. FIXED establishes a specified level, INCLUDE adds detail from selected dimensions, and EXCLUDE removes dimensions from the view's calculation context.

By combining these concepts, analysts can calculate customer-level metrics, regional totals, average order values, first purchase dates, percentages of total, and other business measures. Always check granularity, filter order, and aggregation behavior to ensure that the final visualization answers the intended business question.

Learn more: JustAcademy Tableau Training | Register for a Tableau Course Demo

Official Tableau References

whatsapp