Plot Last 30 days & Last to Last 30 days of data on same chart area

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.

Plot Last 30 days & Last to Last 30 days of data on same chart area1

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:

Plot Last 30 days & Last to Last 30 days of data on same chart area3

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

Plot Last 30 days & Last to Last 30 days of data on same chart area2

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:

Select x.date,x.Sales1,y.Sales2
From table1 as x INNER JOIN table2 as y
On x.Row=y.Row

Share the joy
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Leave a Reply

avatar
  Subscribe  
Notify of