Forum Discussion
Add short month to DATE query syntax.
I found the following on Chris Webb's blog and it works great, however, I need to include the Short month format ie. Jan, Feb, Mar, etc. . What do I need to modify, or can you recommend a different version of this type of code that removes the Input of the start and end dates and grabs the Min & Max date from my MainData source.
let CreateDateTable = (StartDate as date, EndDate as date, optional Culture as nullable text) as table =>
let
DayCount = Duration.Days(Duration.From(EndDate - StartDate)),
Source = List.Dates(StartDate,DayCount,#duration(1,0,0,0)),
TableFromList = Table.FromList(Source, Splitter.SplitByNothing()),
ChangedType = Table.TransformColumnTypes(TableFromList,{{"Column1", type date}}),
RenamedColumns = Table.RenameColumns(ChangedType,{{"Column1", "Date"}}),
InsertYear = Table.AddColumn(RenamedColumns, "Year", each Date.Year([Date])),
InsertQuarter = Table.AddColumn(InsertYear, "QuarterOfYear", each Date.QuarterOfYear([Date])),
InsertMonth = Table.AddColumn(InsertQuarter, "MonthOfYear", each Date.Month([Date])),
InsertDay = Table.AddColumn(InsertMonth, "DayOfMonth", each Date.Day([Date])),
InsertDayInt = Table.AddColumn(InsertDay, "DateInt", each [Year] * 10000 + [MonthOfYear] * 100 + [DayOfMonth]),
InsertMonthName = Table.AddColumn(InsertDayInt, "MonthName", each Date.ToText([Date], "MMMM", Culture), type text),
InsertCalendarMonth = Table.AddColumn(InsertMonthName, "MonthInCalendar", each (try(Text.Range([MonthName],0,3)) otherwise [MonthName]) & " " & Number.ToText([Year])),
InsertCalendarQtr = Table.AddColumn(InsertCalendarMonth, "QuarterInCalendar", each "Q" & Number.ToText([QuarterOfYear]) & " " & Number.ToText([Year])),
InsertDayWeek = Table.AddColumn(InsertCalendarQtr, "DayInWeek", each Date.DayOfWeek([Date])),
InsertDayName = Table.AddColumn(InsertDayWeek, "DayOfWeekName", each Date.ToText([Date], "dddd", Culture), type text),
InsertWeekEnding = Table.AddColumn(InsertDayName, "WeekEnding", each Date.EndOfWeek([Date]), type date)
in
InsertWeekEnding,
#"Invoked FunctionCreateDateTable" = CreateDateTable(#date(2014, 1, 1), #date(2015, 12, 31), null)
in
#"Invoked FunctionCreateDateTable"1 Reply
- MattAllington
Community Champion
If you don't need long month name, just delete one of the M from the line that starts
InsertMonthName.
ie swap "MMMM" with "MMM"
If you need both, then
1 duplicate this same line
2 rename the second of the two lines InsertMonthShort
3 on the second line, change "MonthName" to "MonthShort"
4 on the second line, change InsertDayInt to InsertMonthName
5 on the line starting with InsertCalendarMonth, replace InsertMonthName with InsertMonthShort