M代码如下:
_create_calendar
( optional begin_year, optional end_year )=>
let
y1 = if begin_year <> null then begin_year else if end_year <> null then end_year else Date.Year( DateTime.LocalNow() ) ,
y2 = if end_year <> null then end_year else if begin_year <> null then begin_year else Date.Year( DateTime.LocalNow() ) ,
tbCalendarSetting = { Number.From ( #date( Number.From( y1),1,1)) .. Number.From( #date( Number.From( y2 ) , 12, 31 )) },
转换为表 = Table.FromList(tbCalendarSetting, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
重命名的列 = Table.RenameColumns(转换为表,{{"Column1", "日期"}}),
更改的类型 = Table.TransformColumnTypes(重命名的列,{{"日期", type date}}),
插入的年份 = Table.AddColumn(更改的类型, "YearID", each Date.Year([日期]), type number),
插入的季度 = Table.AddColumn(插入的年份, "QuarterID", each Date.QuarterOfYear([日期]), type number),
插入的月份 = Table.AddColumn(插入的季度, "MonthID", each Date.Month([日期]), type number),
插入的每年的某一周 = Table.AddColumn(插入的月份, "WeekOfYearID", each Date.WeekOfYear([日期]), type number),
插入的某一日 = Table.AddColumn(插入的每年的某一周, "DayID", each Date.Day([日期]), type number),
#"插入的每周的某一日 " = Table.AddColumn(插入的某一日, "DayOfWeekID", each Date.DayOfWeek([日期],1), type number),
年份名称 = Table.AddColumn(#"插入的每周的某一日 ", "年份", each "Y" & Text.From([YearID]) ),
季度名称 = Table.AddColumn(年份名称, "季度", each "Q"&Text.From([QuarterID])),
月份名称 = Table.AddColumn(季度名称, "月份", each Date.MonthName([日期]) ),
年周名称 = Table.AddColumn(月份名称, "年第几周", each "W" & Text.From( [WeekOfYearID] )),
月日名称 = Table.AddColumn(年周名称, "月第几日", each "D" & Text.From( [DayID] )),
周几名称 = Table.AddColumn(月日名称, "周几", each Date.DayOfWeekName( [日期] ))
in
周几名称
网友评论