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.

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

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.

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

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:

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

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

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.

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.

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.

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:

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:

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.

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.

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

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 ❤

Product Manager @tableau; formerly @edXOnline and @ericsson | @OlinCollege