Tableau Tip: Group Years into Decades Using Calculated Fields

In a recent Tableau project, I wanted to divide a long span of years into decades, as this would provide a more visually effective way to grasp the growth of revenue from top movies (data from The Movie Database) over time. With a little searching, I found the pieces I needed. Below I’ll include a description of my process, followed by links to the helpful sources of insight I found on this topic.

First, here is the visualization with total revenues year by year. Notice that despite its current width you still have to scroll left to reach the early 1900s. Meanwhile, the difference year to year is not in itself that interesting.

Top TMDB movie revenue totals by year a partial view

Now here is the visualization when years are chunked into decades. Much more effective!

Top TMDB movies total revenue by decade

DISCLAIMER: These charts use revenue numbers as entered in The Movie Database by contributors based on publicly reported figures. Thus, the data includes only a portion of all movies. I’ve as yet made no adjustments for inflation.

Getting to Decades from Dates

Now for the process of getting decades from dates. I broke my approach into two steps:

  1. I first created a calculated field to pull the Year from the Release Dates field, using Tableau’s DATEPART function.

    Calculated field to get only the Year from the date information in Release Date

    Once that field was created, I moved the new calculated field from Measures to Dimensions, where it should be.

  2. Then I created a Decades dimension as an additional calculated field. This calculation uses Year and the modulo operator to round each year down to the nearest multiple of 10.

    Calculated field to round each year down to its decade using modulo

    Then, similarly, once created, I made this calculated field a Dimension.
    That’s all it took!

Many thanks to Nick Parsons and Erik Bokobza for their helpful replies in the Tableau Community Forums. Links below.

Recommended Reads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s