Loading

Unexpected Aggregation (Duplicated Values) When Using Row-Level IF Statements with Relationships in Tableau

Udgivelsesdato: Apr 17, 2026
Beskrivelse

In Tableau’s logical model, Relationships are designed to prevent the duplication of measures across tables with different levels of detail. However, certain calculated fields can force Tableau to alter how it queries the data, inadvertently bypassing this smart aggregation behavior.

Consider the following scenario with two related tables:

Table A

Code1Row No.
11
12
13

Table B

Code2Measure
120

The Relationship: [Code1] = [Code2]

Normally, if you bring Code1 and Measure into the view, Tableau relies on the relationship to handle the different levels of detail gracefully. The resulting Measure value will accurately display as 20.

However, users often run into issues when writing a calculated field (let's call it Repro) to conditionally sum the measure based on a specific code:  

SUM(
    IF [Code1] = 1 
    THEN [Measure] 
    END
)

When you add Code1 and the Repro calculation to the view, the result displays as 60 (three times larger than the expected 20).

Why does this happen?

Because the IF statement evaluates [Code1] = 1 without any preceding aggregations, Tableau treats this as a row-level calculation. To evaluate a row-level calculation across two different tables, Tableau must temporarily join the tables together under the hood at the row level of the dimension table (Table A).

Because Table A has three rows where Code1 equals 1, the single row of Measure (20) from Table B is duplicated three times during this row-level evaluation. The outer SUM() function then adds those duplicated rows together (20 + 20 + 20), resulting in 60.

Løsning

To resolve this issue and maintain the smart aggregation benefits of Relationships, the calculation must be written as an aggregate calculation rather than a row-level calculation.

Modify the calculated field to evaluate the condition and the measure at the visualization level of detail:

IF ATTR([Code1]) = 1 
THEN SUM([Measure]) 
END

 

Vidensartikelnummer

005318709

Vedhæftede filer

UnexpectedAggregation.twbx

14 KB

 
Indlæser
Salesforce Help | Article