2 Replies Latest reply on Jul 15, 2015 6:17 PM by David Edwards

# Previous Month Total for Previous Year

Hi Tableau Guru's,

I'm new to Tableau and have been looking on the forum to try and find a solution to my problem, but I can't find anything that matches to what I need. I'm having trouble creating a cross tab that shows last months sales totals compared to last year's total for the same month.

Here's how I calculated last month's totals:

IF DATEDIFF('month',[DATE],TODAY())=1,

THEN [SALES]

END.

I tried to use the same sort of logic to build the formula for the same month for last year:

IF DATEDIFF('year',[DATE],TODAY())=1

AND

DATEDIFF('month',[DATE],TODAY())=1

THEN

[SALES]

END

However it doesn't work. It looks like my assumption on how to build this was wrong. Any help would be greatly appreciated!!!

• ###### 1. Re: Previous Month Total for Previous Year

Hi David,

No tableau guru here, but we fell in to a similar situation.

We made the 'Same Month Previous Year' calculation = 13 rather than having the year datediff in there.

if DATEDIFF('month',[Date],today())=13 then [SALES] end

Still not sure why the Datediff('year' ...) wont work, so might have to go back and investigate.

Hope it helps

Chris

• ###### 2. Re: Previous Month Total for Previous Year

Chris,

Thanks so much! I can't believe I didn't think of that!

-David