itsnotaboutthecell

Auto Calendar and Thoughts

Mar 16th, 2019 (edited)
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. (StartDate as date, EndDate as date, optional Culture as nullable text) as table =>
  2. let
  3. DayCount =
  4. Duration.TotalDays(EndDate - StartDate)
  5. + 1,
  6. Source =
  7. List.Dates(
  8. StartDate,
  9. DayCount,
  10. #duration(1, 0, 0, 0)
  11. ),
  12. // I added the optional metadata header for the third argument - type table [Date = date] removing some unneccasary M
  13. TableFromList =
  14. Table.FromList(
  15. Source,
  16. Splitter.SplitByNothing(),
  17. type table [Date = date]
  18. ),
  19. /* I'm always curious in terms of memory management because PQ supports Int8.Type, Int16.Type, Int32.Type and Int64.Type
  20. but as you force them into the optional argument in the function's or steps which allow a type to be passed it seems to misrepresent them
  21. at least graphically - for instance the [Quarter] below is set as Int8.Type and the header icon should be "1 2 3" denoting whole numbers
  22. though the icon shows 1.2 denoting a decimal number. Also I'm almost 200% positive that once it's actually loaded into the Vertipaq Engine
  23. all values are stored as 64 Bit - it just comes across as extremely wasteful IMHO.
  24. */
  25. InsertYear =
  26. Table.AddColumn(
  27. TableFromList,
  28. "Year",
  29. each Date.Year([Date]),
  30. Int64.Type
  31. ),
  32. InsertQuarter =
  33. Table.AddColumn(
  34. InsertYear,
  35. "Quarter",
  36. each Date.QuarterOfYear([Date]),
  37. Int8.Type
  38. ),
  39. InsertMonth =
  40. Table.AddColumn(
  41. InsertQuarter,
  42. "MonthNr",
  43. each Date.Month([Date]),
  44. Int8.Type
  45. ),
  46. InsertYearMonth =
  47. Table.AddColumn(
  48. InsertMonth,
  49. "YearMonth",
  50. each Date.ToText([Date], "yyyyMM"),
  51. type text
  52. ),
  53. InsertDay =
  54. Table.AddColumn(
  55. InsertYearMonth,
  56. "Day",
  57. each Date.Day([Date]),
  58. Int8.Type
  59. ),
  60. InsertDayInt =
  61. Table.AddColumn(
  62. InsertDay,
  63. "DateInt",
  64. each [Year] * 10000 + [MonthNr] * 100 + [Day],
  65. Int64.Type
  66. ),
  67. InsertMonthName =
  68. Table.AddColumn(
  69. InsertDayInt,
  70. "Month",
  71. each Date.ToText([Date], "MMMM", Culture),
  72. type text
  73. ),
  74. InsertMonthNameShort =
  75. Table.AddColumn(
  76. InsertMonthName,
  77. "Month short",
  78. each Date.ToText([Date], "MMM", Culture),
  79. type text
  80. ),
  81. InsertDayWeek =
  82. Table.AddColumn(
  83. InsertMonthNameShort,
  84. "DayInWeek",
  85. each Date.DayOfWeek([Date], Day.Monday) + 1,
  86. Int8.Type
  87. ),
  88. InsertDayName =
  89. Table.AddColumn(
  90. InsertDayWeek,
  91. "DayOfWeekName",
  92. each Date.ToText([Date], "dddd", Culture),
  93. type text
  94. ),
  95. InsertYearWeek =
  96. Table.AddColumn(
  97. InsertDayName,
  98. "YearWeek",
  99. each
  100. Text.From([Year])
  101. & Text.PadStart(
  102. Text.From(Date.WeekOfYear([Date])),
  103. 2,
  104. "0"
  105. ),
  106. type text
  107. ),
  108. InsertWeekStarting =
  109. Table.AddColumn(
  110. InsertYearWeek,
  111. "WeekStart",
  112. each Date.StartOfWeek([Date]),
  113. type date
  114. ),
  115. InsertWeekEnding =
  116. Table.AddColumn(
  117. InsertWeekStarting,
  118. "WeekEnding",
  119. each Date.EndOfWeek([Date]),
  120. type date
  121. ),
  122. InsertWeekofYear =
  123. Table.AddColumn(
  124. InsertWeekEnding,
  125. "WeekofYear",
  126. each Date.WeekOfYear([Date]),
  127. Int8.Type
  128. )
  129. in
  130. InsertWeekofYear
Add Comment
Please, Sign In to add comment