Often, there is no “right” way to accomplish something in Tableau. There are often many ways to approach a solution. Sometimes there are “better” ways.
I’ve been thinking for a while about a couple of my earliest posts (Dynamic Annotations part 1 and part 2). It occurred to me that I had very much over-complicated the solution. The more I understand how Tableau works, the simpler some things become. It can be fun to struggle and come up with unique and creative solutions but it can be equally satisfying to understand why things work and have clarity on how to achieve certain results.
Dynamic Annotations is one such case. Here is the easy way:
I had previously realized that a mark annotation was associated with a mark and would only show if the mark was shown. My solution to turn annotations on or off was to show or hide certain marks using various calculated measures and dual axes. Whoa! Way too complicated…
What defines a mark? When you see a bar or a circle or shape in Tableau or when you see the text “17 marks” in the lower left status bar, what is it that define those marks?
Tableau draws a mark for every intersection (tuple) of dimension values.
Various other factors can come into play.
Data densification can complete domains of dimensions and cause more marks to be drawn:
Multiple axes can duplicate marks (once for each axis):
Mark annotations are applied on a mark. But what defines whether a specific mark annotation is shown is not just the intersection of dimension values. There are two major factors:
The distinct combination of values for those fields defines a unique mark annotation which will only be shown for that specific set of values.
All of that may seem rather complex — but it leads to a very easy way to create dynamic annotations in Tableau. You can have sets of annotations controlled by parameters or include fields as dimensions on the marks card that will change values based on action filters in a dashboard. The possibilities are endless for dynamically controlling which annotations are shown.
Here’s how I created the sets of annotations shown above: First, I created a parameter that allows the user to decide which set of annotations to see. You’ll notice I used a list of integers with “Display As” text.
Then, I created a calculated field that simply returns the selected value of the parameter.
Then, I just placed that calculated field on the Marks card as a dimension (remember, that is one of the key factors). Then, as I cycle through the parameter options I can annotate marks with whatever annotations I want to have displayed for that particular selection of the parameter.
Wow! That was far easier.