3 Replies Latest reply on Sep 15, 2016 10:21 AM by David Li

# Is it possible to do a Table Calculation for Percent Difference for "Last 12 Months"?

Hi,

I am trying to calculate percentage changes for last rolling 12 months of my date. However, Tableau only allows me to calculate it relative to a given year such as "2015" and "2016". I want to be able to have Tableau count number of records for example August 2015 - September 2016 and then Septmber 2015 - October 2016. The current default method would count everything in 2015, which I don't want.

Is there a way to set a given date range?

Thanks,

Sam

• ###### 1. Re: Is it possible to do a Table Calculation for Percent Difference for "Last 12 Months"?

Hi Sam, one way to do this is to put your months in the columns shelf and then use a lookup function. For instance, something like this:

SUM([Number of Records]) - LOOKUP(SUM([Number of Records]), -11)

Note that the negative number there should be one off from the number of rolling months, since the current one is included. For instance, for a 2-month rolling comparison, the number would be -1.

Also, note that the period August 2015 to September 2016 is 14 months, not 12.

• ###### 2. Re: Is it possible to do a Table Calculation for Percent Difference for "Last 12 Months"?

Hi David,

Thanks for the response!

However, I am not sure that the formula is working properly. My data is appearing like this:

 Country Number of Records Previous 12 Months along Country China 1,570 United States 43 Italy 25 Brazil 20 United Kingdom 15 Colombia 14 India 14 Turkey 13 UAE 13 Pakistan 8 Canada 6 Germany 5 -1,565 Mexico 5 -38 Iraq 4 -21 Kenya 4 -16 PERU 4 -11 Romania 4 -10 Poland 3 -11 Saudi Arabia 3 -10 Vietnam 3 -10 Egypt 2 -6 Ghana 2 -4 GUATEMALA 2 -3 Kuwait 2 -3
• ###### 3. Re: Is it possible to do a Table Calculation for Percent Difference for "Last 12 Months"?

Hi Sam, you have to put months in your columns shelf (or add them to the level of detail in some other way) for this to work. You can hide the months you don't want to display using some table calculation tricks afterwards.