In Tableau workbooks, when relating tables with mismatched keys on the logical layer, you might use an IFNULL calculation to substitute missing values from either table. While this calculation successfully resolves the missing values when placed directly in the view as a dimension, aggregating this calculation (e.g., utilizing it as a sorting measure or inside an aggregation) returns NULL for rows where the relationship keys do not match.
For example, consider the following table structure.
Creating the following calculated fields allows you to complement the missing keys and names across both tables.
Calculation Examples:
However, when aggregating the above calculated fields, NULL is returned for rows with mismatched relationship keys.
As a result, this may lead to unexpected results, such as when using the calculated fields as a sorting criterion.
This behavior is also observed when using equivalent logical expressions such as:
IF ISNULL([Key (table1)]) THEN [Key (table2)] ELSE [Key (table1)] ENDIF ISNULL([Name (table1)]) THEN [Name (table2)] ELSE [Name (table1)] ENDTableau's relationships feature queries tables dynamically based on the context of the fields in the view.
When referencing dimensions from both tables, as seen in the above calculations, the calculated fields are treated as dimensions. When added directly to the view, missing values are correctly filled in.
On the other hand, if you aggregate these calculated fields, they are treated as measures, and the relationship performs an INNER JOIN between both tables. Therefore, when relating tables with mismatched relationship keys, NULL is returned for those mismatched rows.
To display and aggregate mismatched relationship keys correctly, apply one of the following workarounds. Please note that a detailed sample is available in the attached workbook.
Combine the tables using a Full Outer Join instead of logical relationships.
On the Data Source page, drag and drop the first table to the canvas.
Select Open from the menu or double-click the first table to open the join canvas (physical layer).
Drag and drop the second table and configure the join type to Full Outer.
The tables will merge into a single flat table, allowing the aggregated IFNULL calculations to display values for all rows.
Create a master "Data Scaffold" table containing all key variations and join other tables to it.
Prepare a Data Scaffold table that covers all key values.
Position the Data Scaffold table as the left-most table.
Configure Left Join for all other tables to the Data Scaffold in the physical layer.
When building the view, use only the key field from the Data Scaffold as the dimension, eliminating the need for IFNULL logic.
Set up logical relationships using a master Data Scaffold table.
Add the Data Scaffold table on the logical canvas.
Relate each of the other tables to the Data Scaffold.
When building the view, use only the key field from the Data Scaffold as the dimension, eliminating the need for IFNULL logic.
Consider using the field that handles missing values in the view without aggregating it. For example, if you want to sort by the values of the [IFNULL (Key)] field as in the example above, place the [IFNULL (Key)] field at the very beginning of the Rows shelf and hide its header.
005386018
44 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.