-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathCalendar.pq
124 lines (124 loc) · 3.15 KB
/
Calendar.pq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
(StartDate as date, EndDate as date, optional Culture as nullable text) as table =>
let
DayCount =
Duration.TotalDays(EndDate - StartDate)
+ 1,
Source =
List.Dates(
StartDate,
DayCount,
#duration(1, 0, 0, 0)
),
// I added the optional metadata header for the third argument - type table [Date = date] removing some unnecessary M
TableFromList =
Table.FromList(
Source,
Splitter.SplitByNothing(),
type table [Date = date]
),
InsertYear =
Table.AddColumn(
TableFromList,
"Year",
each Date.Year([Date]),
Int64.Type
),
InsertQuarter =
Table.AddColumn(
InsertYear,
"Quarter",
each Date.QuarterOfYear([Date]),
Int8.Type
),
InsertMonth =
Table.AddColumn(
InsertQuarter,
"MonthNr",
each Date.Month([Date]),
Int8.Type
),
InsertYearMonth =
Table.AddColumn(
InsertMonth,
"YearMonth",
each Date.ToText([Date], "yyyyMM"),
type text
),
InsertDay =
Table.AddColumn(
InsertYearMonth,
"Day",
each Date.Day([Date]),
Int8.Type
),
InsertDayInt =
Table.AddColumn(
InsertDay,
"DateInt",
each [Year] * 10000 + [MonthNr] * 100 + [Day],
Int64.Type
),
InsertMonthName =
Table.AddColumn(
InsertDayInt,
"Month",
each Date.ToText([Date], "MMMM", Culture),
type text
),
InsertMonthNameShort =
Table.AddColumn(
InsertMonthName,
"Month short",
each Date.ToText([Date], "MMM", Culture),
type text
),
InsertDayWeek =
Table.AddColumn(
InsertMonthNameShort,
"DayInWeek",
each Date.DayOfWeek([Date], Day.Monday) + 1,
Int8.Type
),
InsertDayName =
Table.AddColumn(
InsertDayWeek,
"DayOfWeekName",
each Date.ToText([Date], "dddd", Culture),
type text
),
InsertYearWeek =
Table.AddColumn(
InsertDayName,
"YearWeek",
each
Text.From([Year])
& Text.PadStart(
Text.From(Date.WeekOfYear([Date])),
2,
"0"
),
type text
),
InsertWeekStarting =
Table.AddColumn(
InsertYearWeek,
"WeekStart",
each Date.StartOfWeek([Date]),
type date
),
InsertWeekEnding =
Table.AddColumn(
InsertWeekStarting,
"WeekEnding",
each Date.EndOfWeek([Date]),
type date
),
InsertWeekofYear =
Table.AddColumn(
InsertWeekEnding,
"WeekofYear",
each Date.WeekOfYear([Date]),
Int8.Type
)
in
InsertWeekofYear