Quantcast
Channel: Desktop topics
Viewing all articles
Browse latest Browse all 213819

DateInt and ISOWeekNumber in Date Table

$
0
0

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:

DateKeyDateIntYearKeyHalfYearKeyQuarterKeyMonthKeyMonthOfYearQuarterOfYearDayOfYearDayOfMonthDayOfWeekMonDayOfWeekSunMonthYearWeekNumberWeekOfYearISO
8/31/2016201608312016201622016320168832443134820163635
8/30/2016201608302016201622016320168832433023820163635
8/29/20162016082920162016220163201688324229128201636

35

 

Can anyone on here help me reconcile the two?


Viewing all articles
Browse latest Browse all 213819

Trending Articles