5 Replies Latest reply on Dec 4, 2016 11:39 PM by Sanket Kelkar

# Get data for previous quarter

Hi All,

I am looking for a solution on below scenario -

I have 2 filters Year and Quarter. For a selected year and a selected quarter, I need to display sum(sales) for selected quarter, previous quarter of same year and selected quarter of previous year.

Eg. If I select year = 2013 and quarter = Q3, I need sum(sales) for following details -

2013 Q3

2013 Q2

2012 Q3

I have tried many ways of getting it in this format but did not find a solution. Can someone please help me ?

TIA,

Sanket.

• ###### 1. Re: Get data for previous quarter

Hi!

I believe you are using parameters for year and quarter selections

if so, create calculated field like (sorry, don't have time to check the code, but it will give you rough idea):

if

( [year field] = [year parameter] and [quarter field] = [quarter parameter] )

or

( [year field] = [year parameter]-1 and [quarter field] = [quarter parameter] )

or

(if [quarter field] >1 then ( [year field] = [year parameter] and [quarter field] = [quarter parameter]-1 ) else  ( [year field] = [year parameter]-1 and [quarter field] = 4) end)

then [sales] else null end

if you have quarter fields as string (Q + integer) then adjust formula to look for integer part in the string.

If this post helped you solve the problem please mark it as 'This helped me'.

• ###### 2. Re: Get data for previous quarter

Hi Sanket...

I think you can find a great video to get you the results you need here:

You will need to add a little logic when looking at Q1 (because the previous quarter will actually be Q4 of last year).

Please let me know if you need a hand

• ###### 3. Re: Get data for previous quarter

Hey Sanket,

See my attached workbook. I created a Parameter based on the Quarter-Year of Order Date, then I created the following fields:

Previous Quarter Sales

Previous Year Sales

TF--this field filters to show only the Date selected in the Parameter. I added this to the Filter.

Hope this helps!

Walt

• ###### 4. Re: Get data for previous quarter

Please note that lookup option will work only when dataset has no 'holes' in it..Tableau does not know what is the 'previous year' in the data. it just takes values from row number specified..

• ###### 5. Re: Get data for previous quarter

This is pretty cool ! Thanks for helping me out Walt.