Forum Discussion
igaca
Helper III
10 years agoPower Query /M version of CALENDARAUTO() DAX function?
Am curious if there is a comparable function in M which looks at the date fields in the available queries and generates a contiguous date table from first to last date value? I am wanting to gene...
Eric_Zhang
Microsoft Employee
10 years ago
According to the BOL, CALENDARAUTO returns a table with a single column named “Date” that contains a contiguous set of dates. The range of dates is calculated automatically based on data in the model. Based on my test, in the model means it would detect the date low and high year boundaries in all tables. Though I'm not familar with Power query, I'd doubt there's an equivalent in Power query.
For copy and paste purpose, you can use a DAX formula as well. Check
DimDate =
VAR fiscal_year_end_month = 3
RETURN
ADDCOLUMNS (
CALENDARAUTO ( fiscal_year_end_month ),
"DateAsInteger", FORMAT ( [Date], "YYYYMMDD" ),
"Year", YEAR ( [Date] ),
"Fiscal Year", IF (
MONTH ( [DATE] ) <= fiscal_year_end_month,
YEAR ( [DATE] ) - 1,
YEAR ( [DATE] )
),
"Quarter", "Q" & FORMAT ( [Date], "Q" ),
"Fiscal Quarter", "Q"
& FORMAT (
IF (
fiscal_year_end_month < MONTH ( [Date] ),
DATE ( YEAR ( [Date] ), MONTH ( [Date] ) - fiscal_year_end_month, 1 ),
DATE ( YEAR ( [Date] ) - 1, MONTH ( [Date] ) + 12 - fiscal_year_end_month, 1 )
),
"Q"
),
"YearQuarter", FORMAT ( [Date], "YYYY" ) & "/Q"
& FORMAT ( [Date], "Q" ),
"Fiscal YearQuarter", IF (
MONTH ( [DATE] ) <= fiscal_year_end_month,
YEAR ( [DATE] ) - 1,
YEAR ( [DATE] )
)
& "/Q"
& FORMAT (
IF (
fiscal_year_end_month < MONTH ( [Date] ),
DATE ( YEAR ( [Date] ), MONTH ( [Date] ) - fiscal_year_end_month, 1 ),
DATE ( YEAR ( [Date] ) - 1, MONTH ( [Date] ) + 12 - fiscal_year_end_month, 1 )
),
"Q"
),
"Monthnumber", FORMAT ( [Date], "MM" ),
"YearMonthnumber", FORMAT ( [Date], "YYYY/MM" ),
"YearMonthShort", FORMAT ( [Date], "YYYY/mmm" ),
"MonthNameShort", FORMAT ( [Date], "mmm" ),
"MonthNameLong", FORMAT ( [Date], "mmmm" ),
"DayOfWeekNumber", WEEKDAY ( [Date] ),
"DayOfWeek", FORMAT ( [Date], "dddd" ),
"DayOfWeekShort", FORMAT ( [Date], "dddd" )
)
Change the 3 to your real fiscal end month accordingly.
VAR fiscal_year_end_month = 3
- igaca10 years ago
Helper III
Great DAX patterns, thank you for that!
If someone knows how to replicate in Power Query, please share. Thanks in advance!
Igor