This blog post is Human-Centered Content: Written by humans for humans.
When I teach LODs in Tableau trainings, I usually set the expectation that it will take a while (and a lot of practice) before students will understand what is going on. That still stands. Teaching the pure concept, though, we can do in ten minutes. I’ll phrase everything like I wished someone had explained it to me many years ago. I’ll also add a few tips and tricks here and there!
The Concept in a Nutshell
Level of Detail = Dimensions by which something is aggregated. If I have three dimensions on rows, columns, color and so on, then my numbers get split down by these dimensions. Those three dimensions are my Level of Detail. There is always exactly one Level of Detail at a time on a sheet. If we want to have our numbers for two or more Levels of Details (aka combinations of dimensions) in the same sheet, we need LOD calculations.
There are three of them: FIXED, EXCLUDE and INCLUDE.
Syntax
The syntax is sometimes a bit daunting for beginners, so let me break it down into its three parts:
- It starts with either FIXED, EXCLUDE or INCLUDE. These three are the only calculations in Tableau Desktop and Web-Edit that are wrapped in curly brackets: {}
- Dimensions: LODs create or adjust levels of details aka combinations of dimensions. We need one or more (or none) dimensions by which we want to aggregate, separated by a comma.
- Aggregation: Every LOD aggregates something, without exception. As such, we need an aggregated field. That’s usually a measure, but can also be another dimension that is aggregated (like date fields).
Important detail: LODs will always have an aggregation within them, but the calculation as a whole will count as a row-level calculation and will be aggregated again in the view.
FIXED
The most popular LOD, FIXED, creates a new level of detail. It does its own thing, not caring about what is happening in the view. The dimensions in a FIXED statement are the level of detail, by which the aggregation afterwards is calculated. Example:
- [Country] and [State] are dimensions on rows.
- Therefore, a measure will be split down by Country and State.
- { FIXED [Country]: SUM([Measure]) } on the other hand will ignore that and just aggregate the measure for the Country. It’s not split down by State.
Pro tip: For the scenario in which we use FIXED and no dimension at all — meaning we pretend there were no dimensions in the view for that aggregation — Tableau recognizes a simplified syntax:
{ FIXED : MAX([Order Date]) } is the same as { MAX([Order Date]) }. This will give us the latest date of the table.
FIXED and the Order of Operations
FIXED differs in two major ways from INCLUDE and EXCLUDE (explained further down): First, it does its own thing, is static and doesn’t care about the dimensions in the view, while the other two do.
Second: FIXED also ignores dimension filters, while the other two do not. A dimension filter is just what it says: a dimension that we put onto the filter shelf. That is due to Tableau’s Order of Operations. If we want a FIXED to be filtered by a dimension filter, we have two options:
- Move the dimension filter into Context. (Right click: Add to context.)
- Add this filter dimension to the dimensions in the FIXED calculation. This is necessary, when there is another FIXED calculation in the view, that must not be filtered by that dimension.
Please note that while a dimension doesn’t filter a FIXED calculation, measure filters (aka a measure on the filter shelf) never filter any LOD. If the measure filter is not aggregated, it can also be put into context. If it is aggregated, then that’s the end of the road.
EXCLUDE
While FIXED does its own thing and ignores what’s happening in the view, EXCLUDE and INCLUDE care about what is happening there. EXCLUDE takes the dimension currently in the view and then throws specific dimensions out for its calculation.
That is especially helpful when the end user of the sheet can determine which dimensions are in the view — for example, with a hierarchy. EXCLUDE will always throw specific dimensions out, but will otherwise adapt to changes in the view. FIXED, on the other hand, will be static and won’t adapt.
{ EXCLUDE [State]: SUM([Measure]) }, for example, will do the same thing as our FIXED before, but will adapt if we add other dimensions to the view.
INCLUDE
INCLUDE is probably the most abstract function in Tableau, although we could just say it does the opposite of EXCLUDE. It also takes the currently used dimensions into account, but adds specific dimensions to it. It’s tricky to wrap our heads around that. Let’s build a simple scenario: I want to compare the sales numbers of my biggest states per country.
Maximum by Country, we can easily get: [Country] onto rows and, for example, [Sales] onto columns. Tableau will take the maximum of all [Sales] rows per [Country]. Problem: We want the maximum of something that is aggregated by our [State]. I first need to take the sum of [Sales] by [State], and then the maximum of that out by [Country].
INCLUDE can help: { INCLUDE [State]: SUM([Sales]) }
Then I can wrap the whole thing in a MAX() or use the maximum directly in the green pill in my view:
Nesting LODs
As stated above, LODs count as row-level calculations, even though they have an aggregation working within them. That means we can and need to aggregate them when we are using them. That has a cool side effect: We can use them as measures in another LOD. That creates a kind of aggregation hierarchy.
Pro tip: Understanding nested constructs is difficult, so here is one rule that helps a lot: We start at the innermost LOD and work our way outwards. It also helps to split the nesting into separate calculated fields and then throw them all into a table to see what they actually do.
LOD Trivia
- LOD is technically the acronym for Level of Detail. Usually, we use that acronym for the LOD calculation, though, while the concept is written out.
- We can replace every FIXED construct with EXCLUDE/INCLUDE and vice versa. The trade-off is what we talked about in the Order of Operations section above.
- Performance-wise, LODs are slow. Nested LODs even more so.
- We can nest LODs in Table Calculations. We cannot nest Table Calculations in LODs.
- When using relationships in the data source, FIXED can move measures from one table to the other by fixing the measure onto a dimension from another table.
- Tableau Prep recognizes FIXED as well since version 2023.1.
- For FIXED, there is an even quicker way to build it: Have a look at Quick LODs.