What are LOD Expressions in Tableau?
LOD expressions in Tableau give you precise control over your calculations, letting you run them at a different level of detail than what is currently in your visualization. They allow you to answer complex business questions by breaking free from the constraints of your viz structure. This article demystifies the three types of LOD expressions - FIXED, INCLUDE, and EXCLUDE - with practical examples to show you exactly how to use them.
What Exactly is a "Level of Detail"?
Before diving into LOD expressions, it’s critical to understand the concept of "level of detail" (or granularity) inside Tableau. The level of detail in any worksheet is determined by the dimensions you are using. These dimensions create the structure of your visualization and define how your measures are grouped or aggregated.
Imagine you have a simple dataset of sales transactions. If you create a bar chart showing SUM(Sales) by Region, the level of detail is the Region. Tableau aggregates all the sales data and gives you one total bar for each region (North, South, East, West).
Now, if you drag the Category dimension onto the Color shelf, the visualization changes. Each regional bar is now segmented into colors representing different product categories (e.g., Technology, Office Supplies, Furniture). The level of detail is now more granular: Region and Category.
Every dimension you add to your view (on Rows, Columns, Color, Detail, etc.) makes the level of detail more granular. LOD expressions are powerful because they let you calculate measures at a level of detail that is different from the one in your view.
The 3 Types of LOD Expressions
LOD expressions give you a way to tell Tableau, "Hey, for this specific calculation, ignore the dimensions in my view and use this other level of detail I'm defining instead." They let you calculate aggregates that aren’t dependent on the dimensions on your worksheet.
The basic syntax looks like this:
{ [LOD TYPE] [Dimension 1], [Dimension 2] : AGGREGATE([Measure]) }{}: The curly braces are key. They signal to Tableau that you're about to write an LOD Expression, not a regular calculation.[LOD TYPE]: This can beFIXED,INCLUDE, orEXCLUDE. This determines how the expression will relate to the dimensions in your view.[Dimension(s)]: This is where you specify the dimension or dimensions you want to use for the calculation. This defines the level of detail for this specific calculation.:: A colon separates your dimensions from your aggregate calculation.AGGREGATE([Measure]): This is the calculation you want to perform, such asSUM([Sales])orAVG([Profit]).
Let's break down each of the three types with real-world scenarios.
1. FIXED LOD Expressions
FIXED LOD expressions compute a value using only the dimensions you specify in the calculation. This calculation completely ignores all other dimensions in your view.
When to use it: Use FIXED when you need a value that remains constant regardless of how users filter or change the granularity of the visualization. For example, finding a customer’s first-ever purchase date or calculating the total sales for an entire region to compare against individual store performance.
Example: Calculating Total Sales Per Customer
Imagine you want to analyze customer value. A useful metric is the total amount of money each customer has ever spent. You want this value to remain the same whether you're looking at their purchases by year, by product category, or by region.
- Create a New Calculated Field.
- Enter the following FIXED expression:
{ FIXED [Customer Name] : SUM([Sales]) }- Name this field "Total Sales per Customer."
This calculation tells Tableau: "For every unique Customer Name in the entire dataset, calculate the total sum of their Sales."
Now, you can use this in a viz. Let’s say you build a view showing SUM(Sales) by Region. If you drag your new "Total Sales per Customer" field onto the view, you can perform new aggregations with it. For example, averaging it will show you the average lifetime value of customers within each region.
A key point about FIXED: It is computed before regular dimension filters are applied. This means if you filter your visualization by "Year = 2023," your FIXED calculation will still show the customer's all-time total sales, not just their 2023 sales. To make a FIXED LOD respect a filter, you have to add that filter to Context (right-click the filter and select "Add to Context").
2. INCLUDE LOD Expressions
INCLUDE LOD expressions compute an aggregate value that includes the dimensions in your view plus any additional dimensions you specify in the expression itself. It essentially calculates at a more granular level than your view.
When to use it: Use INCLUDE when you need to calculate something at a finer level of detail than is displayed and then aggregate that result back up to the view's level. A classic example is finding the average sales per order.
Example: Finding the Average Sales Per Order by Region
Let's say your view shows total sales by Region. If you use AVG(Sales), Tableau will calculate the average of every single line item's sales amount. But what if you want to know the average value of a customer's entire shopping cart (their order)?
The Order ID is at a more granular level than the Region in your view. This is a perfect use case for INCLUDE.
- Create a New Calculated Field.
- Enter the following INCLUDE expression:
{ INCLUDE [Order ID] : SUM([Sales]) }- Name this field "Sales per Order."
This calculation scans the data and computes the total sales for each unique Order ID. It now returns a list of values, where each value is the sum of sales for a specific order.
To use this in your view of sales by Region, you can now drag this "Sales per Order" field onto your view and aggregate it with AVG(). The new field would be AVG([Sales per Order]).
This tells Tableau: "First, find the total sales for every order. Then, for each region, calculate the average of those order totals." This provides a much more meaningful insight than just averaging every individual product sale.
3. EXCLUDE LOD Expressions
EXCLUDE LOD expressions do the opposite of INCLUDE. They compute a value by removing, or excluding, some of the dimensions from your view's level of detail. It allows you to calculate at a coarser granularity than the visualization.
When to use it: Use EXCLUDE when you want to compare a granular value against a more aggregated value. A common scenario is to see how a certain sub-category's sales compare to the total sales of its parent region.
Example: Sub-Category Sales versus Total Regional Sales
Let's say you build a view that shows SUM(Sales) broken down by Region and Sub-Category.
You want to place a second bar next to each sub-category that represents the total sales for the entire region it belongs to. This lets you visually compare the part to the whole.
- Create a New Calculated Field.
- Enter the following EXCLUDE expression:
{ EXCLUDE [Sub-Category] : SUM([Sales]) }- Name this field "Regional Sales Total."
This expression tells Tableau: "For this calculation, even though Sub-Category is in my view, ignore it. Just give me the total SUM(Sales) at the Region level."
Now, drag Region and Sub-Category to the Rows shelf and place both SUM(Sales) and your new SUM([Regional Sales Total]) calculation onto the Columns shelf. You will now see two bars for each sub-category: one for its own sales, and another longer bar (which will be identical for all sub-categories within the same region) showing the total for that region. This makes comparative analysis incredibly powerful.
LOD Expressions vs. Table Calculations
You might be thinking, "This sounds a bit like Table Calculations." While they can solve similar problems, they work very differently.
- Table Calculations operate on the visual table of data that exists within your worksheet. Their output is entirely dependent on the dimensions in the view. If you remove a dimension, the table calculation often breaks or changes its output significantly.
- LOD Expressions compute their values at the data source level. The results they return behave more like fixed values in your dataset, making them more resilient to changes in the visualization. A FIXED LOD, for instance, returns a value that can be reused across different worksheets without changing.
In general, for calculations you want to be portable and independent of a single viz layout, LODs are often the better and more robust choice.
Final Thoughts
Level of Detail expressions are one of Tableau's most powerful features, allowing you to create nuanced and sophisticated analyses that go beyond basic aggregations. By mastering FIXED, INCLUDE, and EXCLUDE, you unlock the ability to answer complex business questions by controlling the precise granularity of your calculations.
Of course, mastering concepts like Tableau LOD expressions requires a considerable time investment. That's why we built Graphed. Instead of navigating the steep learning curve of traditional BI tools and writing complex formulas, we've automated the entire process. You can connect all your data sources and simply ask questions in plain English, like "Compare sales for each clothing sub-category against the total sales for the entire Clothing department." Graphed generates the interactive dashboard for you in seconds, letting your team get insights without needing to become data experts.
Related Articles
How to Enable Data Analysis in Excel
Enable Excel's hidden data analysis tools with our step-by-step guide. Uncover trends, make forecasts, and turn raw numbers into actionable insights today!
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.