Forum Discussion
Calculate Previous Month Value from Dynamic TTM Measure
HI BunnyV ,
It seems like you are calculate rolling across multiple date fields, can you please share some dummy data for test?
How to Get Your Question Answered Quickly
Regards,
Xiaoxin Sheng
- BunnyV6 years agoFrequent Visitor
Anonymous Greg_Deckler amitchandak Thanks for all of your replies.
Please find the below sample data which i am calculating TTM for.
Month VALUE Jan-18 1194 Feb-18 1103 Mar-18 1313 Apr-18 1289 May-18 1363 Jun-18 1317 Jul-18 1518 Aug-18 1560 Sep-18 1474 Oct-18 1420 Nov-18 1487 Dec-18 1526 Jan-19 1437 Feb-19 1459 Mar-19 1650 Apr-19 1470 May-19 1699 Jun-19 1421 Jul-19 1591 Aug-19 1549 Sep-19 1517 Oct-19 1275 Nov-19 1417 Dec-19 1428 Jan-20 197 I have this TTM data table and then, i have create a Calender table which dont have any relation with data table.
But i am using the YEAR column to filter out the years from Calender as a relative filter using another measure.
_TTM Measure is as i mentioned in my question, and the relative filter measure which filters last 12 months is
_TTM =VAR CurrentDate = MAX(TTM[Date])VAR EndDate = MAX(Calender[EOMONTH])VAR PreviousDate = DATE(YEAR(CurrentDate),MONTH(CurrentDate)-11,DAY(CurrentDate))VAR Result =CALCULATE(SUM(TTM[VALUE]),FILTER(ALLSELECTED(TTM),TTM[Date] >= PreviousDate && TTM[Date] <= CurrentDate))VAR MonthNo =CALCULATE(DISTINCTCOUNT(TTM[Month]),FILTER(ALLSELECTED(TTM),TTM[Date] >= DATE(YEAR(CurrentDate),MONTH(CurrentDate)-11,DAY(CurrentDate)) && TTM[Date] <= CurrentDate))RETURNResult/MonthNo----_Last12Months =VAR TTMDATE = MAX(TTM[Date])VAR CurrentDate = MAX(Calender[Date])VAR PreviousDate = DATE(YEAR(CurrentDate),MONTH(CurrentDate)-11,DAY(CurrentDate))VAR SelectedYear = SELECTEDVALUE(TTM[Year])RETURNSWITCH(TRUE(),TTMDATE <= CurrentDate && TTMDATE >= PreviousDate,"12Months","Others")
Output:-Now the values which are coming are absolute fine, and if you see even though i selected the value from YEAR slicer there is no filter applied onto the table because there is no relation from TTM data table to caleder.To filter out last 12 months data accordingly,I put that _Last12Months measure into visual level filter and filteredout the months.But then the values are getting changed and the values are coming wrong.The values which i am getting before filtering 12months are the right values.Can anyone please guide me where is the issue is.Thanks,Bunny.- BunnyV6 years agoFrequent Visitor
- Anonymous6 years agoNot applicable
Hi BunnyV ,
Maybe you can try to add an if statement to filter current and previous year based don selected calendar date:
_TTM = VAR CurrentDate = MAX ( TTM[Date] ) VAR EndDate = MAX ( Calender[EOMONTH] ) VAR PreviousDate = DATE ( YEAR ( CurrentDate ), MONTH ( CurrentDate ) - 11, DAY ( CurrentDate ) ) VAR Result = CALCULATE ( SUM ( TTM[VALUE] ), FILTER ( ALLSELECTED ( TTM ), TTM[Date] >= PreviousDate && TTM[Date] <= CurrentDate ) ) VAR MonthNo = CALCULATE ( DISTINCTCOUNT ( TTM[Month] ), FILTER ( ALLSELECTED ( TTM ), TTM[Date] >= DATE ( YEAR ( CurrentDate ), MONTH ( CurrentDate ) - 11, DAY ( CurrentDate ) ) && TTM[Date] <= CurrentDate ) ) VAR cYear = YEAR ( MAX ( calndar[Date] ) ) RETURN IF ( YEAR ( CurrentDate ) IN { cYear - 1, cYear }, Result / MonthNo )Notice: add a visual filter to hide records who not contain correspond measure results.
Regards,
Xiaoxin Sheng