It is quite easy to use the Rank() function in Tableau itself. However, it is a table calculation which may sometimes complicate things. It can be useful to have the data set ranked before it enters Tableau. Creating the ranks beforehand can help make calculations using those ranks become more simple.
So how do we use Rank() in Tableau prep instead?
It is quite simple actually. To go over it I will use the data from Preppin Data 2023 Week 8 as an example. In the challenge we are asked to rank purchases by date and two other categories. We start by going to the field that we want to rank and finding the rank function:
This is what you will see after selecting rank:
From this menu we can configure the rank function to whatever we need. We can begin by renaming it from Calculation 1, in this case I will just call it Rank. Then we add what we want to group the rank by.
In this case we are grouping by date, market cap groups, and purchase price groups. This means that it will rank each combination of these three separately, so for every date it will look at every combination of market cap and purchase price groups for the rank. We used Purchase Price to being our rank function so it has already been selected for Order by on the right side. However, if we want to change what the function uses to rank by, we can change it from here. We can also choose between Rank, Dense Rank, and Percentile Rank for the type of Rank.