The Level Up series is designed to take Tableau beginners from out-of-the-box functionality to the next level of design and analytics, and features tip and tricks to make your dashboards more professional and polished. Make sure to check out the other posts in the Level Up series before you go!
Tableau graphs allow you to add multiple mark layers, which has a surprising number of uses. Today, I’m going to demonstrate how to make a chart like the ones above. These charts show a time trend over multiple decades (using the line mark), but also call out the specific decade we’re looking at (using the circle mark). The circle moves when the decade parameter is changed, which gives the user a helpful “You Are Here” marker.
To see these charts in action, check out my automotive recalls dashboard.
Step 1: Create the Base Chart
Let’s start by creating the first mark layer on the graph. Mine is a line chart showing the count of safety recall IDs by decade, so I dragged the decade pill to rows, count of IDs to columns, and set the mark type to “Line”.
Step 2: Create a Calculated Field
For my call-out circle, I only want to show the decade that the user has selected. I don’t want to put circles on every mark, just the one they’ve picked. I’m going to create a calculated field that I can use to only show the value that matches the “decade” parameter.
Here’s what my field looks like:
if [Decade]=[Parameters].[Decade] then 1 end
Because I’m counting IDs for my base graph, not summing up values, I’m using a funky calculation here. Here’s how it works: My calculated field is going to return a 1 anytime I have an ID in the matching decade. When I put this into my viz, I’ll use “Sum” as the aggregation. (See the next step for this in action). That means that I’ll be adding 1 for each matching ID, which is the same thing as counting the IDs – I’m using this method so that if the decade doesn’t match, I get “Null” instead of “0”.
If I were summing instead of counting, like in the second graph on the dashboard where I’m summing the number of potentially affected vehicles, this is even simpler. I just want to keep the values that match my decade, and make all the others null. Then I can just keep summing like normal. My calculated field for the second graph would look like this:
if [Decade]=[Parameters].[Decade] then [Potentially Affected] end
To play around with how these fields work, you can download this workbook from Tableau Public.
Step 3: Add the Second Mark
Drag the calculated field you just made to the “rows” shelf, and set the aggregation you want to use. (See Step 2 for why I’m summing now instead of counting). You can apply some basic styling here if you would like – I changed colors and set the second mark card to “Circle”.
Step 4: Create a Dual Axis
Click on the second row pill and select “Dual Axis”
On the “All” marks card, drag off any pills that auto-populated. This will get your graph back to the styles you had set.
Step 5: Synchronize Axes
Right click on the right-hand axis, and select “synchronize axis”. This will bring your two marks layers into alignment. At this point, if your layers aren’t aligning, go back and check your calculated field – something may be wrong there.
You’ll probably also want to uncheck “show header” – since the right axis and left axis are now synchronized, you don’t need both.
Step 6: Clean Up
Now all that’s left is to clean up your graph! Change any styles and sizes you want, hide axes if you don’t want them shown, and right click on the null counter and select “Hide Indicator”.
Thank you for reading! Make sure to check out the rest of the level up series before you go, and subscribe to get notified of new posts.
Leave a Reply