2 Replies Latest reply on Jan 31, 2014 9:58 AM by Bradley Collins

    For a stacked bar chart, how do I display the Top N, but then change the sort order of the bars?

    Bradley Collins

      Hi all,


      I am trying to create a stacked bar chart, but the dimension on the x-axis has too many values to reasonably show at once. I would like to show just the top (or bottom) N of those dimensions at once. But as this plot will be hosted on Tableau Server, the chart needs to also be sortable by the viz user (e.g., if the chart is in Descending order then it should show the *top* 10 customers by total sales, but switching to Ascending order should show the *bottom* 10 customers by total sales). Is there a way to create such a chart?


      Two approaches I've tried without success:

      1) Create a Top N filter on Customer Name based on SUM(sales): This works for only one sort order at a time -- if I set the filter to give me the Top 10 customers in descending order, then the user switches the chart to sort in ascending order, the original filter still applies and the chart doesn't make sense. That is, the customers are first filtered to the 10 highest by sales, then sorted within that 10 so that the "lowest" customer is actually the 10th highest instead of the actual lowest.


      Top 10 + descending order (good):

      Top 10 descending.png


      Top 10 + ascending order (bad):

      Top 10 ascending.png


      2) Create a calculated field = index() and filter on that field: This approach works for a normal (non-stacked bar chart) but not with a stacked bar chart -- at least not without modification. I see that the segment of the bar (Item, in this case) is being taken into account in the Rank = Index() table calculation, which would seem to be a problem, but I can't figure out how to change this:

      Sorting by rank.png


      I've created a dummy workbook to explain this question (attached); one sheet shows method 1, the other sheet shows method 2.


      Thank you for your help!