Forum Discussion
Shifting dates one year back
- 4 years ago
amitchandak pointed me in the right direction such that I could use the inbuilt time shifting functions but ignoring the current day. I'm including this post too if anyone finds it useful, as I wanted MTD last year, but ingoring the current day. Here is the code for that:
MTD previous year = VAR _max = TODAY () - 1 VAR _min = EOMONTH ( _max, -1 ) + 1 RETURN CALCULATE ( [Expression)], DATEADD ( DATESBETWEEN ( dimCalendar[Date], _min, _max ), -1, YEAR ) )
Hi amitchandak thanks for your response, I think we are nearly there, The top formula returned back some of today's numbers, which I wanted to avoid. However, removing the ISFILTERED and MAX date solves that, and brings the correct answer:
Expression =
var _max = today()-1
var _min = eomonth(_max,-1)+1
return
CALCULATE([Measure] ,DATESBETWEEN(dimCalendar[Date],_min,_max))Can you confirm that I have not ruined this so that it will still show the complete previous month on the 1st of the month, and it will still not begin counting this months numbers until the 2nd of the month (but always excluding the current day)?
Thanks again.
amitchandak pointed me in the right direction such that I could use the inbuilt time shifting functions but ignoring the current day. I'm including this post too if anyone finds it useful, as I wanted MTD last year, but ingoring the current day. Here is the code for that:
MTD previous year =
VAR _max =
TODAY () - 1
VAR _min =
EOMONTH ( _max, -1 ) + 1
RETURN
CALCULATE (
[Expression)],
DATEADD ( DATESBETWEEN ( dimCalendar[Date], _min, _max ), -1, YEAR )
)