
1. Re: MAT calculated fields
Jonathan Drummey Jun 24, 2016 9:02 AM (in response to Dimitar Stoimchev)2 of 2 people found this helpfulHi,
Rather than doing this through string manipulation my suggestion is to use dates, for example creating a newTimePeriod field using:
DATEPARSE("YYYYMMdd", [TimePeriod])
If you have a LatestDate column in your data source then you can use that, otherwise you can build one using a FIXED Level of Detail expression:
{FIXED : MAX([TimePeriod])}
The column in the data source is preferable as it will be faster in Tableau.
Then there are a number of ways you can get LAST MAT and PREVIOUS MAT Sales, here's a way that works like what you described.
LAST MAT:
IF [newTimePeriod] >= DATEADD('year',1,[LatestDate]) THEN [Sales] END
PREVIOUS MAT:
IF [newTimePeriod] >= DATEADD('year',2,[LatestDate]) AND [newTimePeriod] < DATEADD('year',1,[LatestDate]) THEN [Sales] END
Jonathan

2. Re: MAT calculated fields
Eleonor Hellblom Mar 16, 2017 6:34 AM (in response to Jonathan Drummey)Hi Jonathan,
Your answer helped me massively, however I am having some issues when I need to do a MAT on another calculated field, as there is then a conflict with aggregation and I haven't fully got my head around that.
I have the following calculation with a FIXED LOD:
(sum([Sales])
/
sum({ FIXED [Country], [Category], [Order Date] : sum([Sales])})
When putting that in the calculation you provided above I get this:
If you or anyone else could help me getting this calculation correct it would be greatly appreciated.
Thank you in advance!