Would you like to learn how to compare two periods of time in Tableau? Here are a couple of ideas on how to achieve this.
Comparing Sales (or any other measure) over different years
Use case: You would like to compare sales over months for all the years available in your dataset. The result you are going for is a line chart that produces one line for each year, so that you can easily see the different in amount of sales per month throughout the years.
How to: The simplest way to achieve this is to leverage Tableau’s built-in date functions. If you want to compare years, for example, you can do the following:
- Drag a Date field to columns. Make sure to show the date as discrete month
- Drag a continuous field to rows (e.g. Sales).
So far, the view will show the amount of e.g. Sales per month aggregating all the years together.
If we want to compare the years, we can simply drag another instance of date to color. This will break down the aggregate amount of Sales per year.
The result should be similar to the image below.
Comparing Sales (or any other measure) over two custom periods
Use case: You want to compare two periods with each other by splitting your dataset into two. Let’s say that you want to compare sales before and after the introduction of a CRM tool, or online orders before and after the pandemic.
How to: You can create two calculated fields and use them to build a dual axis chart. Let’s say that your dataset contains dates from 2017 until 2020. You want to compare sales for 2017 and 2018 together against sales for 2019 and 2020 together.
First of all, create two calculated fields with the desired dates. Let’s call the first calculate field “Period one”, and use the following calculation: IF Year([Date]) <= 2018 THEN [Sales] END
The other calculated field will be called “Period 2” with the following calculation: IF Year([Date]) > 2018 THEN [Sales] END
With these calculations you are telling Tableau: if the date is in the period defined, please return the Sales.
Now use the two calculated fields to build a dual Axis Chart. If you are not familiar with Dual axis charts, check out this video.
Thank you for reading! Hope you had fun and learned more about how to compare periods of time in Tableau.