4 Replies Latest reply on Aug 3, 2016 4:17 AM by khalid norat

# Prior Year vs Current Year Comparison

Hi Everyone,

I am trying to achieve a comparison for Prior year vs Current year data.

I am able to achieve this, however I wants to allow the user to get an option to select the year from a filter.

So when I have all the years selected then CY=2016 and PY =2015

and if the user selects the year = 2015

then CY=2015 and PY=2014

same goes to all the other years.

Regards,

Somok

• ###### 1. Re: Prior Year vs Current Year Comparison

Hi Somok,

I think using a parameter to select the year rather than a filter may be more beneficial in this example if I understand what you want correctly.

I have attached an example workbook which uses such.

Hope it helps!

• ###### 2. Re: Prior Year vs Current Year Comparison

See this one.

• ###### 3. Re: Prior Year vs Current Year Comparison

Hi Somok,

Create a parameter that allows the user to select what year they want to treat as the current year. Then make a calculation that dynamically sets the PY for them as well.

[DateSorter]

IF YEAR([DateField]) = [ParameterYear] THEN 'Current Year'

ELSEIF YEAR([DateField])  = ([ParameterYear] - 1) THEN 'Previous Year'

ELSE 'Other Times'

END

You then can use this in the view and you can remove the 'other times' via the filters shelf.  Further you then can use calculated field that works on top of this field.

SUM(IF [DateSorter] = 'Current Year' THEN [Value] END)

-

SUM(IF [DateSorter] = 'Previous Year' THEN [Value] END)

Which would give the difference between the two. Obvious you may want to do the quotient or the percent difference etc depending on your needs.

This is a very simplified exercise from the blog post that I wrote which you can find here: Date Comparisons in Tableau Made Easy

Cheers!

Carl Slifer

InterWorks

• ###### 4. Re: Prior Year vs Current Year Comparison

Hi Somok

Have a look at this I have made a few amendments.

But I think the output is what you require.

Unfortunately I had to use a slider instead of options for years.

Hope this helps.

Khalid