Welcome back to “When use what?” blog post series…
Today I am going to write about how “Rank_Unique” function can solve your problems in Tableau sometimes!
Consider Superstore as your dataset. Imagine you want to find the TOP 10 products in the East Region by Profit Ratio by Year.
How would you do it in Tableau?
STEP 1
- Drag Order Date and Product Name on Rows
- Drag Profit and Sales on the table
You will get the view below:
STEP 2
- Create a calculated field to get your “Profit Ratio” as below:
- Add it into the view. This is how our table looks like now:
- Drag Region on the Filter Shelf and select only “East”
STEP 3
It is time to create our Rank function. My first attempt was the following calculated field:
Click on the calculated field and select the option “Convert to discrete”, then drag it on rows.
You will see that it won’t do it what you want (you can try, though) even if you edit the table calc…
So, how to solve this issue? The answer is: RANK_UNIQUE!
Instead of the previous calculation, make this one:
It will basically force Tableau to make a unique rank for each row.
Make it discrete, then drag it into the view and do not forget to edit the table calculation (select advanced) in order to let it restart every year:
Then, drag your “rank unique” from the rows on the filter shelf (keep ctrl pressed) and select only the values between 1 and 1o in order to show your top 10.
Below your final table!
Hope you enjoyed it.
A presto!