Level-of-Detail Calculations

A regional sales dashboard can display one mark per region while answering a question about individual customers. For example, average customer spending requires you to total each customer's purchases before averaging those totals. Level-of-Detail Calculations let you control this intermediate grouping without adding every grouping field to the visible chart.

Identify the calculation grain

The grain is the combination of dimensions that identifies one group for a calculation. With Region alone in a view, ordinary SUM(Sales) gives one total per region. Adding Product Category divides each region into smaller groups, so the ordinary sum now describes each region-category combination.


A level-of-detail calculation explicitly controls the dimensions used for an aggregation. Its calculation grain can differ from the grain of the displayed marks. Before writing one, state the business question as a sequence: identify the entities, calculate a value for each entity, and decide how to summarize those values.


For average customer spending within a region, the governing idea is:


Average customer spending=Sum of customer sales totals within the regionNumber of customers with sales in the region\text{Average customer spending} = \frac{\text{Sum of customer sales totals within the region}}{\text{Number of customers with sales in the region}}


Suppose one region has three order-line sales: customer A purchases CAD 80 and CAD 120, while customer B purchases CAD 400. The customer totals are CAD 200 and CAD 400. Their average is CAD 300 per customer; averaging the three original rows instead gives CAD 200 per order line. Both calculations are valid, but they answer different questions.

Choose the scope

The common syntax places a scope keyword and dimensions before a colon, followed by an aggregation:


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


Braces enclose the expression, square brackets identify fields, and SUM specifies what happens within each group. Separate multiple declared dimensions with commas.


Scope

Calculation grain

Typical purpose

FIXED

The declared dimensions, independently of view dimensions

Preserve a named grouping when the view changes

INCLUDE

View dimensions plus declared dimensions

Calculate finer groups before summarizing them

EXCLUDE

View dimensions minus declared dimensions

Provide a broader comparison within detailed marks


For customer spending in a Region-only view, use:


Plain text
{INCLUDE [Customer ID] : SUM([Sales])}


Set this field's display aggregation to Average. INCLUDE first calculates totals at Region plus Customer ID; Average then summarizes those customer totals for each region.


A three-stage flow connects order-line records to customer totals within regions and then regional averages.


In a Region-and-Product-Category view, the following expression removes the category split while retaining Region:


Plain text
{EXCLUDE [Product Category] : SUM([Sales])}


The regional total can therefore appear beside each category's sales. By contrast, FIXED [Region] explicitly names Region as its calculation grain, even if other dimensions enter the view.



Check aggregation and filter behavior

Inspect both the aggregation inside the braces and the aggregation used to display the result. Summing customer totals produces regional sales; averaging them produces average spending per customer. Changing the outer aggregation changes the business question when finer results are summarized.


When a broader total repeats across detailed marks, repetition does not create additional sales. Do not manually add the repeated regional totals across category rows to obtain a company total.


Filter timing also affects meaning. FIXED is evaluated after extract, data-source, and context filters, but before ordinary dimension filters. INCLUDE and EXCLUDE are evaluated after ordinary dimension filters. Thus, an ordinary category filter can restrict visible sales while a FIXED regional denominator still includes all categories. Making that filter a context filter changes the rows available to FIXED.



What to remember

  • State the entity and grouping before choosing a scope.
  • Use FIXED for declared dimensions, INCLUDE to add detail, and EXCLUDE to remove view detail.
  • Match the display aggregation to the intended business measure.
  • Check filter timing before interpreting a comparison or percentage.

Example: Customer spending and regional comparisons

A distributor records the following order-line sales for one reporting month. These are all its records for that month. Each customer belongs to one region, all customer IDs are present, and there are initially no filters. Sales are in Canadian dollars. In Tableau, the numeric sales field is named Sales.


Region

Customer ID

Order-line sales (CAD)

North

N1

120

North

N1

180

North

N2

500

South

S1

240

South

S2

360


North and South contain two customers each, with two order lines for N1 and one for every other customer.


Give monetary results to two decimal places and percentages to one decimal place.


a) A view contains Region as its only dimension. Write an INCLUDE calculation for average total spending per customer, state its display aggregation, and calculate the result for each region.


First total the order lines for each customer within each region. Create a field named Customer Spending with the expression {INCLUDE [Customer ID] : SUM([Sales])}.


Display Customer Spending using Average. Region comes from the view, while INCLUDE adds Customer ID for the intermediate calculation.


The North customer totals are:


SN1=120+180=300.00 CADSN2=500.00 CAD\begin{aligned} S_{N1}&=120+180=300.00\ \text{CAD}\\ S_{N2}&=500.00\ \text{CAD} \end{aligned}


Average the two customer totals:


S‾North=300+5002=400.00 CAD per customer\overline{S}_{\text{North}} =\frac{300+500}{2} =400.00\ \text{CAD per customer}


The South customer totals are CAD ________ and CAD ________:


S‾South=240+3602=300.00 CAD per customer\overline{S}_{\text{South}} =\frac{240+360}{2} =300.00\ \text{CAD per customer}


As a check, averaging North's three original order lines would give approximately 800/3=266.67800/3=266.67 CAD per order line. That is a different measure because N1 contributes two rows. The requested results are CAD 400.00 per customer for North and CAD 300.00 per customer for South.


b) Change the view to Region plus Customer ID. Write an EXCLUDE expression for the regional sales total beside each customer and calculate the values shown.


Remove Customer ID from the calculation grain while retaining Region from the view. Use the expression {EXCLUDE [Customer ID] : SUM([Sales])}.


Sum the sales in each remaining regional group:


SNorth=120+180+500=800.00 CADSSouth=240+360=600.00 CAD\begin{aligned} S_{\text{North}}&=120+180+500=800.00\ \text{CAD}\\ S_{\text{South}}&=240+360=600.00\ \text{CAD} \end{aligned}


The displayed regional comparison values are therefore:

  • North, customer N1: CAD 800.00.
  • North, customer N2: CAD 800.00.
  • South, customer S1: CAD 600.00.
  • South, customer S2: CAD 600.00.

The values repeat because the customer marks are finer than the calculation grain. Repeated totals are comparisons, not additional sales. The actual combined regional sales are 800+600=1400.00800+600=1400.00 CAD; manually adding all four displayed comparison values would count each regional total twice.


c) In the Region-and-Customer-ID view, define Regional Sales using {FIXED [Region] : SUM([Sales])}.


Calculate a customer's share using SUM([Sales]) / MIN([Regional Sales]).


Apply an ordinary Customer ID dimension filter that retains only N1. Find N1's displayed share. Then find the share if that same filter becomes a context filter.


Each mark belongs to one region, so MIN retrieves that region's single FIXED comparison value. With an ordinary Customer ID filter, FIXED is evaluated before the filter removes N2. N1's numerator contains its own sales, while the North denominator still contains both North customers:


N1 sales=120+180=300.00 CADNorth denominator=300+500=800.00 CADDisplayed share=300800×100%=37.5%\begin{aligned} \text{N1 sales}&=120+180=300.00\ \text{CAD}\\ \text{North denominator}&=300+500=800.00\ \text{CAD}\\ \text{Displayed share}&=\frac{300}{800}\times100\%=37.5\% \end{aligned}


When Customer ID becomes a context filter, only N1's rows reach FIXED. The North denominator is recalculated from those rows:


Context-filtered denominator=120+180=300.00 CADDisplayed share=300300×100%=100.0%\begin{aligned} \text{Context-filtered denominator}&=120+180=300.00\ \text{CAD}\\ \text{Displayed share}&=\frac{300}{300}\times100\%=100.0\% \end{aligned}


The first result compares N1 with the original regional customer population. The second compares N1 with the retained customer population. The difference follows from when the filter acts, not from any change to N1's purchases. N1's share is 37.5% with the ordinary dimension filter and 100.0% with the context filter.

A wholesaler's Tableau data contains one row per invoice line. The view contains Account ID and Product Category, with no filters. An account can buy from several categories. What does the following calculation represent at each account-category mark?


Plain text
{FIXED [Account ID] : SUM([Sales])}
Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A retail analyst is reviewing the Tableau calculation { FIXED [Store ID] : SUM([Sales]) } before saving it. Match each syntax component to its role in a level of detail expression.

Match each term
A.

Enclose the entire level of detail calculation.

B.

Lists the fields that specify grouping under the selected rule.

C.

Separates the grouping portion from the calculation performed within each group.

D.

Specifies the summary calculation performed within each group.

E.

Selects the rule governing how grouping relates to the view.

Colon

Scoping keyword

Dimension declaration

Aggregate expression

Curly braces

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A retailer has one row per order line, and customers place different numbers of orders. A Tableau view contains Region as its only dimension. The analyst wants average total sales per customer within each region, giving each customer equal weight within that region. Assume no filters or missing customer IDs. Which calculation and display aggregation meet this requirement?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice