Parameter Actions: Year over Year Comparison

Tableau 2019.2 is now available. Our team is excited to introduce Parameter Actions as part of this awesome release. This feature allows you to visually change a parameter’s value and, as a result, interactively change inputs to your analysis.

In my previous blog post I touched on a variety of use cases Parameter Actions can help with your analysis. Part of those use cases involved time.

In this post I will breakdown how you can build interactive Year over Year (YoY) charts. Contextual labels are added right in the view to let you easily compare percent changes between different time periods.

To demonstrate the power of Parameter Actions, we will look at a dataset of Toronto home prices. Last week I was in Toronto attending one of Tableau’s Customer Success Summits. It was great to catch up with customers and discuss some of the latest interactive analytics features we are shipping this year as well as our vision for the future of Tableau interactivity. I hope this example drives home the new powers this feature gives you.

Image for post
Image for post

We will get started by creating a viz of different Toronto property types over time.

Image for post
Image for post

Then we will create two parameters, “Current Left Date” and “Current Right Date” that will define the left and right boundaries of this year’s analysis window. Each parameter should be defined, as follows.

Image for post
Image for post

With the newly defined parameters we can now place the band in the view.

Image for post
Image for post

Now that we have the current window rendered we need to calculate and show the same period last year. To do so, we will author two calculated fields that each subtract a year from this year’s left and right boundaries. For example:

Image for post
Image for post

Dropping the two new calculated fields in the Marks card Detail shelf as Continuous Exact Dates allows us to render the left reference band.

Image for post
Image for post

However, nothing happens yet when we select marks on the visualization.

Image for post
Image for post

Parameter Actions to the rescue!

We will leverage Parameter Actions to interactively change the two “Current” parameters. One action will pick up my selection’s minimum month value and assign it to the “Current Date Left,” while the other will store my selection’s maximum month value to the “Current Date Right” parameter.

Image for post
Image for post

Now as I select marks in the viz, Tableau updates the position of both reference bands. Mark selection causes the parameters to update, which in turn cause the calculations to update, and the reference bands to re-render.

Image for post
Image for post

We still have to calculate the percent differences for each window and display the metrics in the view. To do so, we will store the average sold price for each band endpoint in a calculation. For example the current left value is defined as follows.

Image for post
Image for post

Same exact syntax applies for the previous year’s window. Then calculating the window’s % difference relative to the previous period is as simple as this:

Image for post
Image for post

Same exact process applies for the previous year’s window. Now, in order to interactively show the % difference labels in the center of each band, we need to find each windows date midpoint. For the right window, we will write the following expression:

Image for post
Image for post

This calculation finds the difference, in months, between the band’s endpoints, divides that number by 2, takes the floor of that, and adds this many months to the band’s left endpoint.

Note that the midpoint date value will not always be in the middle. Since Tableau needs a row in the data to draw the mark, in the case where the number of month marks between the endpoints is even, such mark doesn’t exist, and we floor the result and draw it offset to the left.

We will then create a calculation that will only return values for which the middle date in each window matches a date in the data table. This will effectively be the y position the label is drawn on.

Image for post
Image for post

Now we have to finally place the right value as Label for the “Label Y Position” mark. For this we will author a different calc, “Value Placer”, that returns the already calculated % difference calculations for each window.

Image for post
Image for post

We can now place the “Label Y Position” on Rows and Dual Axis the two panes so the labels and trends are superimposed.

Image for post
Image for post

I hope this walkthrough helps you see how you can leverage Parameter Actions to interactively answer a very common business question. This new feature allows you and your consumers to quickly inspect trends in a viz and get to insights faster!

Go play with Parameter Actions and let us know what you think!

There’s more magic coming soon ❤

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store