Advance with Assist shares quick solutions to common challenges encountered by the InterWorks Assist on-demand team.
Question: I thought this would be easy and just a check somewhere, but I can’t figure out how to reverse the order of the colors. As new months are added, they go to the left. I want them on the right. What is the magic sauce?
Well, this person was right—it is just a button to select. But understanding what Tableau is doing here is important.
To sort this the way the client is requesting, you need to right-click on the MONTH(Date) pill on Color and click Sort. By default, Tableau selects Ascending. By changing to Descending, the months will be in order from left to right:
Now, another question comes up: January is the first month, but alphabetically February is before January, so why does this work? The answers are in how Tableau handles dates. When a date is recognized, Tableau gives the full hierarchy of the date for use in the Tableau visualizations. But what is really happening?
Let’s look at the exact same date hierarchy, but we’ll make it a calculated field instead of Tableau’s date hierarchy. Below, I’ve created a calculated field just like the date hierarchy pill:
Now, when we add this to the Label card, we can see that MONTH returns the month number. January = 1, February = 2, and so on:
Tableau’s date hierarchy gives the month name or date part rather than the month number or date value. In the background, though, the date value or number is what Tableau is using for the sorting.