Forum Discussion
hardcode last month date
- 5 years ago
Hi Anonymous ,
My formula is based on Today(), I don't think it will result in moving month in the forward months. Did you have a Date table in your date model?
My understanding for your case is when today is 2021/7/1 Then all the months forward will show value for 2021 June. If today is 2021/6/30 . All the months forward will show value for 2021 May.
A little modification of my formula :
Measure = VAR A = IF ( RIGHT ( FORMAT ( TODAY (), "YYYYMM" ), 2 ) = "01", VALUE ( FORMAT ( TODAY (), "YYYYMM" ) ) - 100 + 11, VALUE ( FORMAT ( TODAY (), "YYYYMM" ) - 1 ) ) RETURN CALCULATE ( [MEASURE], FILTER(ALL(Date),Date[yearmonth] = A ))If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Best Regards,
Dedmon Dai
- 5 years ago
Hi Anonymous ,
For example, today is 2020/1/1, so its yearmonth equals to 202001, if you need to get the previous month it is 2019 Dec, its yearmonth column should be 201912, so I use -100+11 in the formula. Similarly, if today is 2019/1/1 the yearmonth for previous month is 201812 = 201901-100+11.
If today is 2020/2/1, its yearmonth equals to 202002, the previous month 's year month 202001 =202002-1. The condition in if formula is used to distinguish the first month of a year and other months.
Best Regards,
Dedmon Dai.
Hi Anonymous ,
My formula is based on Today(), I don't think it will result in moving month in the forward months. Did you have a Date table in your date model?
My understanding for your case is when today is 2021/7/1 Then all the months forward will show value for 2021 June. If today is 2021/6/30 . All the months forward will show value for 2021 May.
A little modification of my formula :
Measure =
VAR A =
IF (
RIGHT ( FORMAT ( TODAY (), "YYYYMM" ), 2 ) = "01",
VALUE ( FORMAT ( TODAY (), "YYYYMM" ) ) - 100 + 11,
VALUE ( FORMAT ( TODAY (), "YYYYMM" ) - 1 )
)
RETURN
CALCULATE ( [MEASURE], FILTER(ALL(Date),Date[yearmonth] = A ))
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Best Regards,
Dedmon Dai
thanks ALOT!!!!! you really saved me hours of headache!!!!! i wish you a very very good day 🙂