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
| Code1 | Row No. |
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
Table B
| Code2 | Measure |
| 1 | 20 |
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).
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.
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
005318709
14 KB

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.