top of page

Welcome
to NumpyNinja Blogs

NumpyNinja: Blogs. Demystifying Tech,

One Blog at a Time.
Millions of views. 

From Confusion to Clarity: Tableau LOD Expressions

Nov 10
4 min read

 Have You Ever Wondered Why Your Tableau Numbers Keep Changing?

“Creating a chart in Tableau is easy. Understanding why the numbers change when you modify the chart is where real analytical thinking begins.”

Imagine spending hours creating a beautiful Tableau dashboard. Your charts look perfect. Your filters are working. Your KPI cards display the expected values. Then you add another dimension to your visualization.

Suddenly, your numbers change! Your average is different. Your patient count looks unexpected. Your calculated field produces a result you didn't anticipate.

And you start wondering:

“Why is Tableau changing my calculations when I only added another field?”

If you have experienced this, you are not alone.

While working on healthcare analytics dashboards, I discovered that one of the most challenging parts of Tableau is understanding how calculations behave at different levels of detail. That is where Level of Detail (LOD) expressions become incredibly useful.

Let's understand this concept with a simple example.


 First, What Does Level of Detail Mean?

In Tableau, Level of Detail refers to how detailed or summarized your data is within a visualization.

Imagine a healthcare dataset containing the following information:

Patient ID

Department

Hospital Stay (Days)

P101

ICU

5

P101

ICU

5

P102

ICU

8

P103

General Ward

3

P104

General Ward

4

Notice something interesting?

Patient P101 appears twice.

This can happen in healthcare datasets when multiple records are collected for the same patient.

Now suppose we want to calculate the average hospital stay.

If we simply calculate:


AVG([Hospital Stay (Days)])


Tableau averages all five rows:

(5 + 5 + 8 + 3 + 4) / 5 = 5 days

But what if our goal is to calculate the average stay per unique patient?

We have only four unique patients.

The correct patient-level average would be:

(5 + 8 + 3 + 4) / 4 = 5 days

In this example, both results happen to be the same!

But that's only a coincidence.

If P101 appeared five times instead of twice, the row-level average would change even though the number of unique patients remained the same.

This is the problem LOD expressions can help us solve.


 What Exactly Is an LOD Expression?

An LOD expression allows you to tell Tableau:

“Calculate this value at the level I specify, regardless of how detailed my visualization is.”

Tableau supports three main types of LOD expressions:

  1. FIXED

  2. INCLUDE

  3. EXCLUDE

Each serves a different purpose.

Let's explore them using healthcare examples.


FIXED LOD: Calculate at a Specific Level

The FIXED expression calculates a value using the dimensions you explicitly specify.

For example, suppose a patient has multiple records in the dataset.

You want to identify the maximum hospital stay recorded for each patient.

Create a calculated field:

Patient-Level Hospital Stay


{ FIXED [Patient ID] : MAX([Hospital Stay (Days)]) }


How Does It Work?

  • FIXED tells Tableau to calculate at a specified level.

  • [Patient ID] identifies the dimension used for grouping.

  • MAX() returns the maximum hospital stay within each patient's records.

For our example, Tableau produces:

Patient ID

Patient-Level Stay

P101

5

P102

8

P103

3

P104

4

Now each patient has one defined stay value.

Important: The calculated value is still repeated across the original rows for that patient. A FIXED expression does not physically remove duplicate records.

To calculate a patient-level average across the entire dataset, you can create another calculation:


{ FIXED : AVG(

    { FIXED [Patient ID] : MAX([Hospital Stay (Days)]) }

) }


However, nested LOD calculations require careful validation, particularly when patient records represent multiple hospital visits.

For datasets containing multiple admissions, it may be more appropriate to calculate the stay at the admission level rather than the patient level.


When Is FIXED Useful?

FIXED expressions are useful for calculating:

  • Patient-level measurements

  • Customer-level sales

  • First purchase dates

  • Department-level benchmarks

  • Overall KPIs

FIXED helps you define exactly which dimensions should control a calculation.


INCLUDE LOD: Add More Detail to Your Calculation

Sometimes, your visualization displays summarized information, but your calculation needs to consider a more detailed level. This is where INCLUDE becomes useful.

Imagine you are analyzing hospital stays by department. Your visualization contains only the Department field.

However, you want to calculate the average of individual patient stays within each department.

You can use:


{ INCLUDE [Patient ID] :

    MAX([Hospital Stay (Days)])

}


Then place the calculated field in your visualization and use the AVG aggregation.

Why Is This Useful?

Without INCLUDE, Tableau may calculate an average directly from all underlying rows.

With INCLUDE, you can ask Tableau to consider each patient within the department before calculating the displayed average.

For example:

ICU patients:

  • P101 = 5 days

  • P102 = 8 days

Average ICU stay = 6.5 days

General Ward patients:

  • P103 = 3 days

  • P104 = 4 days

Average General Ward stay = 3.5 days

The calculation respects the department shown in the visualization while including patient-level detail.

INCLUDE adds detail to a calculation without requiring you to display that detail in the chart.


 EXCLUDE LOD: Remove Detail from Your Calculation

Now imagine you are creating a sales dashboard. Your visualization displays sales by Region and Product Category. But you want to compare each category against the total sales of its region. You don't want the regional benchmark to change for every product category.

This is where EXCLUDE becomes useful.

Create a calculated field:

Regional Sales Total


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


What Happens?

Suppose your data contains:

Region

Category

Sales

East

Furniture

$20,000

East

Technology

$30,000

West

Furniture

$15,000

West

Technology

$25,000

The calculation produces these regional totals:

East Region: $50,000

West Region: $40,000

Even when Category appears in the visualization, the EXCLUDE expression removes Category from the calculation's level of detail.

This allows you to compare individual category sales with the broader regional total.

EXCLUDE removes selected dimensions from the calculation while keeping them visible in your chart.


An Easy Way to Remember

FIXED: Calculate at this level.

INCLUDE: Add this level of detail.

EXCLUDE: Ignore this dimension when calculating.


  My Biggest Learning


“The secret to mastering Tableau isn't creating complicated calculations. It's understanding the question behind every calculation.”

And that is what makes data analytics exciting.

Every calculation teaches us something.

Every challenge improves our analytical thinking.

And every dashboard brings us one step closer to turning data into meaningful insights.

 Keep Learning, Keep Exploring, and Never Be Afraid of Complicated Concepts!

“The concepts that confuse us today often become the skills that make us confident tomorrow.”

 

 
 

+1 (302) 200-8320

NumPy_Ninja_Logo (1).png

Numpy Ninja Inc. 8 The Grn Ste A Dover, DE 19901

© Copyright 2025 by Numpy Ninja Inc.

  • Twitter
  • LinkedIn
bottom of page