3 Replies Latest reply on Mar 7, 2017 8:33 AM by venky v

    Sort on Table Calc

    venky v

      Hello All,

      I have a calculated field for example SUM(Sales)/Attr({SUM(Sales}). When I drag any dimension on to my viz I want to sort it by field (calculated field:SUM(Sales)/Attr({SUM(Sales})). Is it possible?



        • 1. Re: Sort on Table Calc
          Simon Runc

          hi Venky,


          So this is an Aggregated calc (with an LoD element), and not a Table Calc...but that doesn't change your issue!


          So one way to force a sort in Tableau, is to take advantage of the way that Blue pills sort anything to it's right in Ascending order, which means the negative sorts in descending order.


          So I've taken your calculation, and then created a negative version of it. I change this to Discrete (Blue) and pop it to the left of the thing I want to sort, and voila (you can then hide the header)


          Hope that helps.

          • 2. Re: Sort on Table Calc
            Stephane Marx



            Because of the LOD formula on sales you cannot. You need to use a rank function on the calculated field you created and to turn it to discrete.
            The step by step explanation below:

            Taking a data set of total population by country. When we simply import the data and use country name by total count of population, the visualization looks something like this

            Raw data of Country wise total population

            Showing this data as it it will not make any sense for the end user. As a problem statement, we want to see which country has the highest count of total population and so on. To achieve this we will try to sort this data in descending order

            Sorting of data

            Once you have clicked on the sorting icon, your data visualization should look something like this

            Final sorted data

            Now that we have the sorted data, we would like to show the Rank of the country as well. To use the rank functionality, let us first duplicate the column data. Clicking CTRL + Selecting the column data will duplicate the column data. Final result will show us two similar visulaizations

            Duplicate column data

            Once you have duplicated the column data, click on the corner drop down arrow and go to Quick table calculation and then further select the Rank option.

            Selecting Rank

            After clicking on the rank option, your data visualization should look something like this

            After Ranking the data

            Now, to show the rank of the country drag down the ranked calculation to row field

            Changing column data to row data

            If you observe here, the visualization has changed and ranked information is grouped together with the total population specific data. Although, this is the correct visualization but this will create more confusion for the end user. To make it more simpler and clear, we will be using the Discrete option.

            Discrete visualization

            After using the discrete option, the final visualization should look like this

            Final discrete visualization

            credits to: Tableau: Using Sorting and Ranking functionality on data set |


            Hope this helps,



            • 3. Re: Sort on Table Calc
              venky v

              Thanks that works.