I had a requirement in tableau where I need to sort the dimension column based on some condition. In tableau you have lot of flexibilities in almost everything but you need to understand how to use them. You can sort generally on alphabetic order, in ascending order, descending order, or you can provide manual order where you can enter the values and ask tableau to sort based on the manual order , you can also order by a specific field. (Here the field can be either direct dimension/measure or any calculated field.)
The scenario in my case is I have a report where I need to order the report in descending order based on the "current level" and again I have another column "new level" which should also follow some order. Like if the new level is greater than the current level then should be shown first and then if it is reverse it should be shown next. Something like if a person is promoted then he should be shown first and demoted should be shown next in the same current level list.
Example if a person's current level is "L" and he is promoted to next level "M" and if another person's current level is "L" and he is demoted to previous level "K" then it should show as below
Current level New level
L M
L K
As you see here it looks very simple to you like you can just sort the current level in descending and the new level in also descending which will solve the problem, but the actual fact is the levels in a company are not in alphabetical order:
like first it will be CEO, CTO then K,L,M and so on. A person can be promoted from K to CTO or demoted to L which cannot be achieved with the help of simple sorting. So for this I first created a RankofCurrentLevel calculated field which looks like below

and then I created the same formula for new level strategy also. Then I created another calculated field to define if a particular person is promoted / demoted as shown below:
Now I dragged and dropped RankofCurrentLevel field and PromotionDemotion field onto the Rows shelf and did the required sorting. But since we don't need to show the values of these fields in the report we need to hide them by following the below steps:
No comments:
Post a Comment