KNOWLEDGE BASE

Incorrect Sorting While Using Secondary Data Source Filters


Published: 24 Nov 2015
Last Modified Date: 01 May 2018

Issue

When you filter a view by a field from a secondary data source, the sorting in your view might appear to be incorrect. 

Environment

Tableau Desktop

Resolution

Option 1: Use the discrete measure

  1. Select Analysis > Create Calculated Field
  2. In the Calculated Field dialog box that opens, do the following, and then click OK:
    1. Name the calculated field. In this example, the calculated field is named "Negative Measure"
    2. In the formula field, create a calculation similar to the following: -SUM([Measure])
  3. Right-click [Negative Measure] in the data pane and select Convert to Discrete
  4. Drag [Negative Measure] to the left most position on the Rows shelf
  5. Right-click [Negative Measure] and uncheck Show Header
Note: For ascending order, do not add the negative.
 

Option 2: Use RANK()

  1. Select Analysis > Create Calculated Field
  2. In the Calculated Field dialog box that opens, do the following, and then click OK:
    1. Name the calculated field. In this example, the calculated field is named "Sorting Rank"
    2. In the formula field, create a calculation similar to the following: RANK_UNIQUE(SUM([Measure]))
  3. Right-click [Sorting Rank] in the data pane and select Convert to Discrete
  4. Drag [Sorting Rank] to the left most position on the Rows shelf
  5. Right-click [Sorting Rank] and uncheck Show Header

Cause

When filtering on a field from a secondary data source, the data is hidden, rather than filtered out. Because the sort is based on the underlying data in the primary data source, the resulting values in the view appear to sort incorrectly.

Additional Information

For more information, see the example workbook available in the attachment section of this article. 
Did this article resolve the issue?