Sorting our data

To make more sense of the data, we need to slice and dice the data in various ways and also look at it from various angles.

Being able to sort the data in ascending, descending or even in a custom manual order will help us put the data into a certain specific order and categorize it better.

Let's say we have around 1,000 customers in our data. Just showing the customers in a random order may not be of much use to us. However, if we sort the customers in descending order by profit, we can see the most profitable customers at the top and the lowest profitable customers at the bottom. However, sorting these customers in ascending order by profit will give us lowest profitable customers at the top followed by the most profitable customers at the bottom.

An example of a manual sort could be sorting the regions in a specific way so that it reads NEWS (North, East, West, and South).

There are various ways of sorting the data in Tableau. Let us look at the steps in the following recipe.

Getting ready

We will continue working in the same workbook, My first Tableau Workbook, and will use the already connected Orders data from our Sample - Superstore.xlsx Excel file. Let us follow the steps in the following recipe to learn how we can sort the data in Tableau.

How to do it…

  1. To begin with, let us first create a new sheet by pressing Ctrl + M on our keyboards and rename it as Sorting.
  2. Since there are some new datasets that we have added in our workbook, let's make sure we select Orders (Sample - Superstore) to enable the Dimensions and Measures of that dataset. Once we do that, drag Sub-Category from the Dimensions pane and drop it into the Rows shelf, followed by dragging Sales from the Measures pane and dropping it into the Columns shelf. This will result in a bar chart as shown in the following screenshot:
    How to do it…
  3. In the preceding bar chart, we will see that the product sub-categories are listed in alphabetical order from A-Z. However, we will sort this in descending order by Sales by using the shortcut sorting option in the toolbar. Refer to the following image:
    How to do it…
  4. One is for the ascending sort and the other is for the descending sort. Let us click on the descending sort. Once we have selected the descending sort, we should see the view as shown in the following image:
    How to do it…
  5. This is one way to sort the chart. Notice the Blue pill of Sub-Category in the Rows shelf; once the sorting is applied, we will see that the pill also has a Sort indicator. The other way to sort is by clicking on the axis. Refer to the following image:
    How to do it…
  6. The preceding approach works perfectly well when there is a single measure. However, imagine having two measures. One on the axis and the other in the Color shelf. The problem with the above sorting method is that, even when we have two measures, this sorting method will only sort by the field that is placed on the axis. Let's look at this. On the same sheet, let's now get Profit from the Measures pane and drop it into the Color shelf. Refer to the following image:
    How to do it…
  7. In the current view, the length of the bars indicates the amount of Sales, whereas, the color of the bars indicates the amount of Profit. Thus, the longer the bar, the larger the Sales figure; and the darker the blue the greater the level of Profit. Further, the bar chart is currently sorted in descending order of Sales. Imagine having to sort with respect to Profit. If we hover over the sorting icons in the toolbar, it will say Sort Sub-Category ascending by Sales or Sort Sub-Category descending by Sales. Thus, in order to sort by Profit, we will have to use another approach.
  8. We will click on the drop-down menu of the Blue pill of Sub-Category in the Rows shelf and click on the Sort… option. Refer to the following image:
    How to do it…
  9. Once we do that, we will get to see the following view:
    How to do it…
  10. Notice that we also have a Manual sort option. However, since we need to sort our product Sub-Categories by Profit, we will select either the Ascending or the Descending option. In this instance, select the Descending option. Next, we will select the Field option and, from the dropdown, select Profit and keep the aggregation as Sum. Refer to the following image:
    How to do it…

How it works…

The preceding view may not look sorted if we look at the length of the bars. However, if we look at the color of the bars, we will see that the bars are sorted by color which is Profit. So, the bar with highest Profit is dark blue in color which is right on the top. This is followed by bars that have lighter and lighter shades of blue which are then followed by shades of orange to indicate losses.

Another option to sort is from the Dimensions pane. If we select the Default Properties option by right-clicking on the Dimensions that needs to be sorted, then we will get a Sort… option. Refer to the following image:

How it works…

If we set the sort order for a field in the Dimensions pane by using the Default Properties option, then it becomes the default sort order for the entire workbook whereas if we set the sort order for a field in the view, then the sort order applies only to the specific sheet view.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.135.225