I got a very unique request from client to show in my tableau dashboard. Actually they got this idea from Google Analytics, they want to show last 30 days and last to last 30 days of data on the same graph. So they want two line charts on the same axis.
Let me elaborate this, they want me to create a line chart, that will show last 30 days of data on the basis of each day. Say suppose, y–axis will have Sales, and x-axis will have dates of last 30 days. On this same chart they want to see what was the sales figure on same day of previous month. So, if Sales=$300 on 15th May, so they want to plot 15th April Sales figure.
I didn’t found a way to do this in Tableau, so I have done this in SQL and used this query in tableau to achieve the target.
We will be having two separate tables of data as:
Let’s visualize it in this way, we need 3 columns to plot the line chart:
1.Date column of last 30 days
2.Sales column for last 30 days
3.Corresponding sales figure on same day of last month
There is no key to join above two tables, so while creating table1 and table2 create an extra column Row no as ROW_NUMBER() OVER (ORDER BY date) AS Row
So on the basis of this Row no we can do inner joins of these two tables:
From table1 as x INNER JOIN table2 as y