KNOWLEDGE BASE

Nested Sort Incorrect When Filtering by Field from Secondary Data Source


Published: 18 Jul 2017
Last Modified Date: 19 Jul 2017

Issue

When filtering a view, which has a nested sort using INDEX(), by a field from the secondary data source then the nested sort may be in the incorrect order

Environment

Tableau Desktop

Resolution

Use RANK() instead of INDEX(). The attached example workbook uses the sample data set Superstore to demonstrate the following directions:
  1. Create a calculated field with a name like "Sort by Rank" with a calculation similar to the following:
    RANK( SUM([Number of Records] ))
  2. Right-click [Sort by Rank] in the data pane and select Convert to Discrete.
  3. Drag [Sort by Rank] to the Rows shelf just before the last dimension on the Rows shelf.
    • By default, Tableau Desktop will compute RANK() by Table (down), which will return the expected sort order, but unexpected ranks.
  4. To correct the rank values, right-click [Sort by Rank] and select Compute Using > Pane (down).
  5. Right-click [Sort by Rank] on the Rows shelf and uncheck Show Header.

Cause

The function INDEX() uses the values from the underlying data to compute the index numbers, but underlying values are not filtered by fields from the secondary data source.

Because we specify an aggregated measure inside of RANK(), the RANK() function uses the values as they are computed in the view.
Did this article resolve the issue?