How can Tableau help compare year-on-year sales?
Ever wondered how your company sales are performing compared to the previous year? Fear not, you are in the right place! Today, I’ll demonstrate how Tableau can help compare year-on-year sales in a simple chart. Let’s get started…
First thing to do is connect to a datasource. For this visualization we will be using the famous Superstore Data which is a sample dataset available in tableau. You can access it from the home screen itself as shown below. It is the second last option in the connection pane on the home screen.
Once you have connected to the data you will have to create a parameter which will give you the option to select a year which will be our current year. This feature gives the visualization more dynamic control.
To create a parameter simply click on the arrow beside the search option and select ‘Create Parameter’ as shown below:
After clicking you should get a configuration pane as follows. Set it up as shown in the image.
I have named my parameter as ‘Select Year’ and changed the data type to Date. After this, I need to get all the years that are in my data. To do that I have to change ‘Allowable values’ from All to List and select the appropriate field from where Tableau will take years. To do that follow the images below:
We will also have to make sure that Tableau just shows the years and not the whole date. You can do that by changing the ‘Display Format’ as follows.
Congrats, you have successfully created a parameter and configured it. The only step left out is to show this parameter on the workbook. You can do that simply by right clicking on the parameter and selecting ‘Show Parameter’ as follows
Now we have a parameter which will let us select a year and compare sales of that year to the previous year. To make this work we will need two calculations. One which will show us the sales for the selected year and a second one will show the sales for the previous year. The calculations are shown below.
This Year Sales:
IF DATETRUNC('year',[Order Date]) = DATETRUNC('year',[Select Year]) THEN [Sales] END
The above calculation just returns the value of sales when the year of order date matches the year of select year parameter.
Previous Year Sales:
IF DATEDIFF('year',[Order Date],[Select Year])=1 THEN [Sales] END
The above calculation returns the value of sales when the difference between the year of order date and select year parameter is 1.
Now you have everything required to build a chart. So, lets get to it. To build a chart first drag sub-categories to rows as shown below.
After this you will have to drag our newly calculated sales fields into columns. It will look something like this once you have done that.
This view does show the sales for this and previous year, but, it is not actually comparing both. To do that we will need to convert this into a ‘dual axis chart’. Simply right click on one of the measures in columns and select dual axis.
Don’t worry if your chart looks weird, we are going to fix that. It should look something like this.
Do you see how the measure values now have a straight line in between them compared to the round edges we had previously? The next step is to synchronize these axes so that they both show the correct values. To do that, right click on the top axis and click on ‘Synchronize Axis’
Now to fix the chart and make it more readable, I will be changing this year sales as bar chart and previous year sales as lines or gantt chart. This can be done by changing the chart type from ‘Automatic’ to ‘Bar’ for This Year Sales and ‘Gantt Bar’ for ‘Previous Year Sales’.
Now, to make it look clean we will just hide the top axis as both of them have the same values. You can do that by right clicking on the axis and deselecting ‘Show Header’.
And voila! There you have your chart which compares sales of a selected year to previous year. You can select different years to see the transitions. Just a few more minor changes and you will have a chart that is perfect and insightful!
What is the The Information Lab Ireland’s Graduate Training Program?
The Information Lab Ireland’s Graduate Training Program is a two-and-half-year program for people with drive and a desire to try something new in data.
When they join us, most of our candidates are completely new to Tableau and Alteryx. After a 14-week intensive training course, they become part of our consulting team, available for long-term engagements with our clients.
We train our graduates in both the technical and soft skills required to be a top-class data analytics consultant.
Want to join us?
When we are hiring, we will post any recruiting news and event information on our blog. So keep your eyes out here.
The Information Lab Ireland is at the forefront of creating a data-driven culture in Ireland.
As part of its vision, The Information Lab Ireland regularly hosts free events throughout the country to show how being data-driven can improve decision making and lead to a better understanding of the world around us. For more on these events please like us on Facebook, follow us on Twitter or catch up with us on LinkedIn