How to plot rank deviations



In this post, we are going to talk about how to plot two Ranks, and show the deviations between them. This post will be done using Superstore, and does not require any data modelling.

The goal of this viz is to allow users to compare two measure ranks among dimensions.

Step 1: Setting up the Ranks

The first thing we need to do is create a Parameter that allows the user to determine which measure they want to use as the Primary Rank (The 45 degree line). To do this, we want to first setup a simple Parameter.


Once we have our Parameter, we want to create a calculation to grab the rank of the measure selected.

[Primary Rank]

IF [Choose Primary Rank] = 'Sales'
THEN RANK(SUM([Sales]))
ELSE RANK(SUM([Profit]))
END

This calculation is simply switching between the Rank of Sales or Profit, based on the user selection.

Now that we have our Primary Rank, we need to find the Secondary Rank, or the rank of the measure we want to plot the deviation to.

[Secondary Rank]

IF [Choose Primary Rank] = 'Sales'
THEN RANK(SUM([Profit]))
ELSE RANK(SUM([Sales]))
END

This is the inverse of the Primary Rank, we simply grab the rank of whatever measure the user did not select.

Step 2: Plotting

Now that we have our calculation, the next step is to start plotting them.

We begin by placing our Primary Rank on the Columns Shelf, and Sub-Category (or whatever dimension you want to compare ranks on) onto the detail shelf. Set the Primary Rank to compute using that dimension.



Perfect, now we want to repeat this same process, placing the Primary Rank again on the Rows Shelf. This will create our 45 degree line of the Primary Rank, showing where those fall.

We also want to Reverse the Column Axis so that is starts at our lowest rank, and moves to the highest (1).


Well at this point, all we have is a line...

The next trick is to drag the Secondary Rank onto the Axis of the Row Shelf. The will generate the Measure Values/Names onto Tableau.


Once that is generated, Set the Secondary Rank to compute using the Dimension, in this case, Sub-Category. Also, reverse the Axis on the Rows shelf (same as column) so that 1 (our highest rank) is at the top.


Perfect, now that we have the bones of the Plot, we just need to do some cleanup.

Step 3: Cleanup

First thing we want to do is remove Measure Names from the Color Mark, and place it instead on the detail shelf. We are going to create another calculation to determine the color.


Now onto the color. We want a calculation that will auto-magically give us the difference between the Primary and Secondary Rank, so that we can better highlight the deviations.

[Color]

[PrimaryRank] - [Secondary Rank]

By taking the difference from the Primary and Secondary Rank, we will always get the Increasing/Decreasing value based on the user's Parameter Selection, as both of these calcs are determined by it.

Place that onto the Color Mark, compute using the Dimension (Sub-Category).


You can change color pallets if you wish, but using a Diverging palette, be sure to set the Center to 0, so that increase/decrease deviations have two different color.

The last thing we need to do is handle how to tell the user what is what. Since Axis Titles are not Data-Driven, we cannot change those at will. So instead we will rename our Axis to be Primary and Secondary Rank.

Then we will create a calculation we can place in the title that will inform our users on which is which.

[Title]

IF [Choose Primary Rank] = 'Sales'
THEN 'Primary Rank: Sales | Secondary Rank: Profit'
ELSE 'Primary Rank: Profit | Secondary Rank: Sales'
END  

There are many different ways you could do this, but I wrapped my into a calc for ease of use.

Place that on the Detail Mark, then simple add it to the Title.


And that's it. You can adjust this in whatever way you need for your data. You can even expand this by having multiple measures, and letting the user select both the Primary and Secondary Rank using two parameters.

Hope this helps!


Previous
Next Post »
0 Comment