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 dedmon,
thanks alot for your suggestion but your measure results in a "moving month" as well. I need the month to be static for the rest of the year. meaning if its july now then we should filter june for the rest of the year. but when we move into aug, we should filter july data and use that for the rest of the year. like a drag on formula.
- Ashish_Mathur5 years agoSuper User
Hi,
Refer to this article - LASTNONBLANK Explained