Creating a custom date table question.
I have been working with M to create a more responsive date table but I have found my knowledge to be lacking in the area requred to create certain fields. DateInt and ISOWeekNumber would be two of those fields. I think I can handle the other fields but I am going to provide all of the details below in case someone can help me clean it up as well.
My current query is this:
let
Source = List.Dates,
#"Invoked FunctionSource" = Source(#date(2014, 1, 1), Duration.Days(DateTime.Date(DateTime.FixedLocalNow()) - #date(2014,1,1)), #duration(1, 0, 0, 0)),
#"Table from List" = Table.FromList(#"Invoked FunctionSource", Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Added Index" = Table.AddIndexColumn(#"Table from List", "Index", 1, 1),
#"Renamed Columns" = Table.RenameColumns(#"Added Index",{{"Column1", "Date"}}),
#"Added Custom" = Table.AddColumn(#"Renamed Columns", "Year", each Date.Year([Date])),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Month Number", each Date.Month([Date])),
#"Added Custom2" = Table.AddColumn(#"Added Custom1", "Day", each Date.Day([Date])),
#"Added Custom3" = Table.AddColumn(#"Added Custom2", "Day Name", each Date.ToText([Date],"ddd")),
#"Added Custom4" = Table.AddColumn(#"Added Custom3", "Month Name", each Date.ToText([Date],"MMM")),
#"Reordered Columns" = Table.ReorderColumns(#"Added Custom4",{"Date", "Index", "Year", "Month Number", "Month Name", "Day", "Day Name"}),
#"Added Custom5" = Table.AddColumn(#"Reordered Columns", "Quarter Number", each Date.QuarterOfYear([Date])),
#"Duplicated Column" = Table.DuplicateColumn(#"Added Custom5", "Year", "Copy of Year"),
#"Renamed Columns1" = Table.RenameColumns(#"Duplicated Column",{{"Copy of Year", "Short Year"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns1",{{"Short Year", type text}}),
#"Split Column by Position" = Table.SplitColumn(#"Changed Type","Short Year",Splitter.SplitTextByRepeatedLengths(2),{"Short Year.1", "Short Year.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Position",{{"Short Year.1", Int64.Type}, {"Short Year.2", Int64.Type}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Short Year.1"}),
#"Renamed Columns2" = Table.RenameColumns(#"Removed Columns",{{"Short Year.2", "Short Year"}}),
#"Added Custom6" = Table.AddColumn(#"Renamed Columns2", "Quarter Year", each Number.ToText([Short Year]) & "Q" & Number.ToText([Quarter Number],"00")),
#"Reordered Columns1" = Table.ReorderColumns(#"Added Custom6",{"Index", "Date", "Day", "Day Name", "Month Number", "Month Name", "Quarter Number", "Quarter Year", "Short Year", "Year"}),
#"Changed Type2" = Table.TransformColumnTypes(#"Reordered Columns1",{{"Date", type date}, {"Day", Int64.Type}, {"Index", Int64.Type}, {"Month Number", Int64.Type}, {"Quarter Number", Int64.Type}, {"Month Name", type text}, {"Quarter Year", type text}, {"Year", Int64.Type}}),
#"Renamed Columns3" = Table.RenameColumns(#"Changed Type2",{{"Day", "DayofMonth"}}),
#"Inserted Day of Year" = Table.AddColumn(#"Renamed Columns3", "DayOfYear", each Date.DayOfYear([Date]), type number),
#"Sorted Rows" = Table.Sort(#"Inserted Day of Year",{{"Date", Order.Descending}}),
#"Renamed Columns4" = Table.RenameColumns(#"Sorted Rows",{{"Date", "DateKey"}}),
#"Duplicated Column1" = Table.DuplicateColumn(#"Renamed Columns4", "Year", "Year - Copy"),
#"Renamed Columns5" = Table.RenameColumns(#"Duplicated Column1",{{"Year - Copy", "YearKey"}, {"Month Number", "MonthOfYear"}, {"Quarter Number", "QuarterOfYear"}}),
#"Inserted Week of Year" = Table.AddColumn(#"Renamed Columns5", "WeekOfYear", each Date.WeekOfYear([DateKey]), type number),
#"Renamed Columns6" = Table.RenameColumns(#"Inserted Week of Year",{{"WeekOfYear", "WeekNumber"}})
in
#"Renamed Columns6"
What I need is this:
DateKey | DateInt | YearKey | HalfYearKey | QuarterKey | MonthKey | MonthOfYear | QuarterOfYear | DayOfYear | DayOfMonth | DayOfWeekMon | DayOfWeekSun | Month | Year | WeekNumber | WeekOfYearISO |
8/31/2016 | 20160831 | 2016 | 20162 | 20163 | 20168 | 8 | 3 | 244 | 31 | 3 | 4 | 8 | 2016 | 36 | 35 |
8/30/2016 | 20160830 | 2016 | 20162 | 20163 | 20168 | 8 | 3 | 243 | 30 | 2 | 3 | 8 | 2016 | 36 | 35 |
8/29/2016 | 20160829 | 2016 | 20162 | 20163 | 20168 | 8 | 3 | 242 | 29 | 1 | 2 | 8 | 2016 | 36 | 35
|
Can anyone on here help me reconcile the two?