Forum Discussion
Creating a Prior Month Indicator Column - that works year over year
- 3 years ago
Hey DJBAJG ,
this DAX statement shows how to create a running month index column:calendar = var dateStart = DATE( 2022 , 1 , 1 ) var dateEnd = DATE( 2023 , 12, 31 ) return ADDCOLUMNS( CALENDAR( dateStart , dateEnd ) , "runningMonthIndexCalendar" , var YearsNoOf = YEAR( [Date] ) - YEAR( dateStart ) var MonthNoOf = MONTH( [Date] ) return YearsNoOf * 12 + MonthNoOf )Here is a screenshot that shows that the index is incremented from December 2022 to January 2023.
Using this index will help to get the previous month's name or will help to shift dates by months for more sophisticated date-related calculations.
This adds a column to the calendar table that holds the prev month name:, "Year Month (prev)" , var eomprev = EOMONTH( [Date] , -1 ) return FORMAT( eomprev , "YYYY MMM" )Another screenshot:
Regards,
Tom
Hey DJBAJG ,
this DAX statement shows how to create a running month index column:
calendar =
var dateStart = DATE( 2022 , 1 , 1 )
var dateEnd = DATE( 2023 , 12, 31 )
return
ADDCOLUMNS(
CALENDAR(
dateStart
, dateEnd
)
, "runningMonthIndexCalendar"
, var YearsNoOf = YEAR( [Date] ) - YEAR( dateStart )
var MonthNoOf = MONTH( [Date] )
return
YearsNoOf * 12 + MonthNoOf
)
Here is a screenshot that shows that the index is incremented from December 2022 to January 2023.
Using this index will help to get the previous month's name or will help to shift dates by months for more sophisticated date-related calculations.
This adds a column to the calendar table that holds the prev month name:
, "Year Month (prev)"
, var eomprev = EOMONTH( [Date] , -1 )
return
FORMAT( eomprev , "YYYY MMM" )
Another screenshot:
Regards,
Tom
Hi Tom
How would I go about incorporating this DAX into an existing calendar? I believe this builds a new calendar table from scratch with hard coded start and end dates. I'll need dynamic date capabilities as new data is added monthly.
Thanks.
Played around and got it to work.
Here's how to add it to an existing calendar table: