'Dynamic Sorting in Tableau Table

I am new to Tableau and one of my tasks if to show top 10 brands.

I have 3 columns: Profit, Sales, and NPS.

The data looks something like this:

| | Profits | Sales | NPS | | --- | --- | --- | --- | | Nike | 10m EUR | 32m EUR | 0.91 | | Adidas | 6m EUR | 21m EUR | 0.88 | | Levi | 12m EUR | 27m EUR | 0.94 |

I know how to select Top 10 brands based on Profits or Sales or NPS individually, but how do I make it so that when the user sorts by Profits it gets top or lowest 10 profitable brands based on sort type (ascending or descending). Similarly the same for Sales and NPS.

Outcome when sorting by Profits (desc):

| | Profits | Sales | NPS | | --- | --- | --- | --- | | Levi | 12m EUR | 27m EUR | 0.94 | | Nike | 10m EUR | 32m EUR | 0.91 | | Adidas | 6m EUR | 21m EUR | 0.88 |

Outcome when sorting by NPS (asc): | | Profits | Sales | NPS | | --- | --- | --- | --- | | Zignov | -23K EUR | 193K EUR | -0.85 | | R&R | -94K EUR | 202K EUR | -0.74 | | Bumble | -133K EUR | 89K EUR | -0.69 |

Current Implementation: Right now, the dashboard displays top 10 brands by Profits, when I want to sort them by NPS, it resorts the same 10 brands, instead of from the complete dataset.



Solution 1:[1]

This can be achieved using a properly scoped Rank(). Ranks are tableau calculations such they are can only be used with an aggregated field, and are functionally identical to an SQL analytical expression.

I helped out another user in the Tableau forum with a near identical problem to yours, my answer is the second one here: https://community.tableau.com/s/question/0D54T00001Ii0QYSAZ/actions-are-not-working-in-top-n-customers-view-while-selecting-any-data-point-in-other-views

The difference for you is that you'll be best off creating two near identical calcs, one running descending to create a sort, the other running ascending to act as the filter.

Let me know how you get on.

Steve

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steve Martin