Edit: if you use a new release of Tableau equal or above 2020.x, you will find an easier way to build a barchar race following the link below:
If you use Tableau 2019.x or below, I invite you to read what is following 🙂
Most of us have encountered Bar Chart Race animations by the time you read me. Can we build it in Tableau? I would say YES and NO, It can be done but using the page shelf which is not available on the web versions of our dashboards.
Let me talk first about who inspired me to do this. John Burn-Murdoch, I invite you to follow him on twitter, deserves an award for building and sharing THIS:
The animation is so smoothed, catchy, I want to stay in it forever and ever. It invites us to know more about the rise and fall of those cities. And we can definetely hear a speaker voice behind this Bar Chart Race (Hans Rosling style).
In Tableau, we can use the page shelf to fake animation, each new value in the page field being a “frame”.
And we can use Tableau to display points, lines and polygons wherever we want! (Once we crack the code 🙂 )
Sooooo… we have everything needed to fake one! (and build anything we want in Tableau, but this is an other debate)
We will use a main dataset with the information we want to animate. In the example, I have four fields: link, year, category and value.
We will use a second dataset with two fields to build each bars: link, point.
And, that’s the new thing, we will use a third dataset to fake each frame.
If you want to show a race by year and have monthly measures too, you can try an alternative and better version of this by skipping this third dataset and use the month and year field to animate the viz!
In Tableau, join this three datasets on link as a cartesian product.
What we want to do now is to display each bar at the right position regarding its ranking by year, for each value in category. We also want the bar to “move” from the current position to a next one.
Let’s begin the calculations!
anim_inter : usefull later for moving values
frame : usefull later for page shelf (if you have a real field, like month, it’s better!)
value_current : value for the current year
value_next : value of the next year
value_inter : value moving linearly from the current to the next year (if you have real values, it’s better!)
rank_current : rank of the current year
rank_next : rank of the next year
rank_inter : rank moving linearly from the current to the next year
@x_inter : moving lenght of the bar
IF min([Point])=1 THEN 0
ELSEIF min([Point])=2 THEN [value_inter]1.0
ELSEIF min([Point])=3 THEN [value_inter]1.0
ELSEIF min([Point])=4 THEN 0
@y_inter : moving position of the bar
IF min([Point])=1 THEN [rank_inter]1.0
ELSEIF min([Point])=2 THEN [rank_inter]1.0
ELSEIF min([Point])=3 THEN [rank_inter]+0.5
ELSEIF min([Point])=4 THEN [rank_inter]+0.5
filter : to filter my top 10 if available
label : display labels on my polygons (you can display what you want/need)
IF min([Point])=1 THEN min([Category])
ELSEIF min([Point])=3 THEN str(int([value_inter]/1000000))+”M”
This last step is not perfect. Who am I to know if my values move linearly a year to an other? That’s why it’s better if you use real values instead of my value_inter.
Now it is time to visualize. You have to use @x_inter and @y_inter inf columns and rows shelves, frame in Pages, filter in Filters.
You have to use the Polygon Mark and use year, category, anim_inter in details, and Point in Path.
We will use the @y_inter again as a dual axis as a point Mark to display my labels.
You won’t see the bars because we need to configure the table calculations.
@x_inter will be computed as Year, and frame.
@y_inter will be computed as Category for rank_current, by Category, Year and frame for rank_next and restarting every Category.
@filter will be computed as Category for filter, Year and frame for value_next.
And… TADAAAA, a Bar Chart Race in Tableau using the page shelf commands.
I updated my first dataset to show information about population by countries by year and whitout modifying anything else: