Fixing “Incorrect” Sorts

本笔记只做复习以及巩固知识点使用,初次学习请下载练习工作簿,跟随网络课程的讲解同步操作,结果参考解法工作簿。

“Incorrect” Sorts

Sometimes our sorts look wrong. Here, we have a bar chart of Proft by Customer ID, with customers broken out by Ship Mode. If we do a quick sort on the axis – what’s going on?

It looks like our sort is incorrect. If we right click on the pill where we see this sort icon, Customer ID, and click sort, we see what’s actually happening. We sorting Customer ID by Proft. That’s it. Ship Mode does not factor into the sort at all.

Fixing “Incorrect” Sorts_第1张图片

If we keep only a bar that appears to be incorrectly sorted, we’ll see this customer has orders with multiple ship modes. Our original sort was being done on customers by overall sum of Profits, despite the fact those Profits may span Ship Modes. So inside of the First Class pane, this customer should not have been ranked so highly, but when we take into account the other orders in a different ship mode, they are highly profitable customer.

Fixing “Incorrect” Sorts_第2张图片

If what we intend to do is sort the customers independently per Ship Mode, we need to tell Tableau exactly how to sort by using a table calculation.

Using RANK

First, right click in the data pane and select “Create Calculated Field”. We’ll name it “Rank”, and then we’ll use the Rank function. Now we have to say what we want to rank, and how. We want to see our bars arranged by profit, so let’s drag that field in, and we
need to have aggregation around that Measure, we’ll use SUM, and close the parentheses. We can also set how the rank should be sorted, we’ll choose ‘desc’. And click OK.

An important step is to convert this field to discrete – by right clicking and selecting “Convert to Discrete”. Now, we’ll bring that field into our view. We see that we have a rank,1,2,3,4 as expected. But what we actually want to do is move the rank between ship mode and customer ID because we want to first consider Ship Mode, then rank by profit.

We can see that the ranks here are 5, 9, 16… those “missing” ranks are just in other ship modes. To make the ranks independent per ship mode, we need to right click and set the compute using to pane down. Now our sorts look correct.

If we don’t want to see the rank in the view, we can right click on the pill on the rows shelf and uncheck Show header. Now our view has the sort we intended and looks tidy!

Fixing “Incorrect” Sorts_第3张图片
image.png

你可能感兴趣的:(Fixing “Incorrect” Sorts)