Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hello,
I have some unique requirements for a date dimension file specifically around unique requirements to show if a date is in a month and quarter as well as the number of week. We use a 4/4/5 week schedule and the first week can have more than 7 days in it. For example for 2022, Jan 1st to Jan 8th is considered week 1 of the year even though it has 8 days because Jan 2nd is the first Sunday of the year. The fiscal month of January actually ends on Feb 4th (4weeks), Feb ends on March 4th (4 weeks) and March ends on April 2nd (5 weeks). The 1st quarter, therefore, ends on April 2nd.
M code similar to below:
let
// configurations start
Today=Date.From(DateTime.LocalNow()), // today's date
FromYear = 2018, // set the start year of the date dimension. dates start from 1st of January of this year
ToYear=2021, // set the end year of the date dimension. dates end at 31st of December of this year
StartofFiscalYear=7, // set the month number that is start of the financial year. example; if fiscal year start is July, value is 7
firstDayofWeek=Day.Monday, // set the week's start day, values: Day.Monday, Day.Sunday....
// configuration end
FromDate=#date(FromYear,1,1),
ToDate=#date(ToYear,12,31),
Source=List.Dates(
FromDate,
Duration.Days(ToDate-FromDate)+1,
#duration(1,0,0,0)
),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Date"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}}),
#"Inserted Year" = Table.AddColumn(#"Changed Type", "Year", each Date.Year([Date]), Int64.Type),
#"Inserted Start of Year" = Table.AddColumn(#"Inserted Year", "Start of Year", each Date.StartOfYear([Date]), type date),
#"Inserted End of Year" = Table.AddColumn(#"Inserted Start of Year", "End of Year", each Date.EndOfYear([Date]), type date),
#"Inserted Month" = Table.AddColumn(#"Inserted End of Year", "Month", each Date.Month([Date]), Int64.Type),
#"Inserted Start of Month" = Table.AddColumn(#"Inserted Month", "Start of Month", each Date.StartOfMonth([Date]), type date),
#"Inserted End of Month" = Table.AddColumn(#"Inserted Start of Month", "End of Month", each Date.EndOfMonth([Date]), type date),
#"Inserted Days in Month" = Table.AddColumn(#"Inserted End of Month", "Days in Month", each Date.DaysInMonth([Date]), Int64.Type),
#"Inserted Day" = Table.AddColumn(#"Inserted Days in Month", "Day", each Date.Day([Date]), Int64.Type),
#"Inserted Day Name" = Table.AddColumn(#"Inserted Day", "Day Name", each Date.DayOfWeekName([Date]), type text),
#"Inserted Day of Week" = Table.AddColumn(#"Inserted Day Name", "Day of Week", each Date.DayOfWeek([Date],firstDayofWeek), Int64.Type),
#"Inserted Day of Year" = Table.AddColumn(#"Inserted Day of Week", "Day of Year", each Date.DayOfYear([Date]), Int64.Type),
#"Inserted Month Name" = Table.AddColumn(#"Inserted Day of Year", "Month Name", each Date.MonthName([Date]), type text),
#"Inserted Quarter" = Table.AddColumn(#"Inserted Month Name", "Quarter", each Date.QuarterOfYear([Date]), Int64.Type),
#"Inserted Start of Quarter" = Table.AddColumn(#"Inserted Quarter", "Start of Quarter", each Date.StartOfQuarter([Date]), type date),
#"Inserted End of Quarter" = Table.AddColumn(#"Inserted Start of Quarter", "End of Quarter", each Date.EndOfQuarter([Date]), type date),
#"Inserted Week of Year" = Table.AddColumn(#"Inserted End of Quarter", "Week of Year", each Date.WeekOfYear([Date],firstDayofWeek), Int64.Type),
#"Inserted Week of Month" = Table.AddColumn(#"Inserted Week of Year", "Week of Month", each Date.WeekOfMonth([Date],firstDayofWeek), Int64.Type),
#"Inserted Start of Week" = Table.AddColumn(#"Inserted Week of Month", "Start of Week", each Date.StartOfWeek([Date],firstDayofWeek), type date),
#"Inserted End of Week" = Table.AddColumn(#"Inserted Start of Week", "End of Week", each Date.EndOfWeek([Date],firstDayofWeek), type date),
FiscalMonthBaseIndex=13-StartofFiscalYear,
adjustedFiscalMonthBaseIndex=if(FiscalMonthBaseIndex>=12 or FiscalMonthBaseIndex<0) then 0 else FiscalMonthBaseIndex,
#"Added Custom" = Table.AddColumn(#"Inserted End of Week", "FiscalBaseDate", each Date.AddMonths([Date],adjustedFiscalMonthBaseIndex)),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"FiscalBaseDate", type date}}),
#"Inserted Year1" = Table.AddColumn(#"Changed Type1", "Year.1", each Date.Year([FiscalBaseDate]), Int64.Type),
#"Renamed Columns1" = Table.RenameColumns(#"Inserted Year1",{{"Year.1", "Fiscal Year"}}),
#"Inserted Quarter1" = Table.AddColumn(#"Renamed Columns1", "Quarter.1", each Date.QuarterOfYear([FiscalBaseDate]), Int64.Type),
#"Renamed Columns2" = Table.RenameColumns(#"Inserted Quarter1",{{"Quarter.1", "Fiscal Quarter"}}),
#"Inserted Month1" = Table.AddColumn(#"Renamed Columns2", "Month.1", each Date.Month([FiscalBaseDate]), Int64.Type),
#"Renamed Columns3" = Table.RenameColumns(#"Inserted Month1",{{"Month.1", "Fiscal Month"}}),
#"Removed Columns" = Table.RemoveColumns(#"Renamed Columns3",{"FiscalBaseDate"}),
#"Inserted Age" = Table.AddColumn(#"Removed Columns", "Age", each [Date]-Today, type duration),
#"Extracted Days" = Table.TransformColumns(#"Inserted Age",{{"Age", Duration.Days, Int64.Type}}),
#"Renamed Columns4" = Table.RenameColumns(#"Extracted Days",{{"Age", "Day Offset"}}),
#"Added Custom1" = Table.AddColumn(#"Renamed Columns4", "Month Offset", each (([Year]-Date.Year(Today))*12)
+([Month]-Date.Month(Today))),
#"Changed Type2" = Table.TransformColumnTypes(#"Added Custom1",{{"Month Offset", Int64.Type}}),
#"Added Custom2" = Table.AddColumn(#"Changed Type2", "Year Offset", each [Year]-Date.Year(Today)),
#"Changed Type3" = Table.TransformColumnTypes(#"Added Custom2",{{"Year Offset", Int64.Type}}),
#"Added Custom3" = Table.AddColumn(#"Changed Type3", "Quarter Offset", each (([Year]-Date.Year(Today))*4)
+([Quarter]-Date.QuarterOfYear(Today))),
#"Changed Type4" = Table.TransformColumnTypes(#"Added Custom3",{{"Quarter Offset", Int64.Type}}),
#"Added Custom4" = Table.AddColumn(#"Changed Type4", "Year-Month", each Date.ToText([Date],"MMM yyyy")),
#"Added Custom5" = Table.AddColumn(#"Added Custom4", "Year-Month Code", each Date.ToText([Date],"yyyyMM")),
#"Changed Type5" = Table.TransformColumnTypes(#"Added Custom5",{{"Year-Month", type text}, {"Year-Month Code", Int64.Type}})
in
#"Changed Type5"
Data looks like this:
MONTH | WEEK # | WEEK ENDS | NUMBER OF WEEKS | Working Days |
JANUARY | 1 | Jan. 08 2022 | ||
2 | Jan. 15 2022 | 4 | ||
3 | Jan. 22 2022 | |||
4 | Jan. 29 2022 | 20 | ||
FEBRUARY | 5 | Feb. 05 2022 | ||
6 | Feb. 12 2022 | 4 | ||
7 | Feb. 19 2022 | |||
8 | Feb. 26 2022 | 2/21 Presidents' Day | 19 | |
MARCH | 9 | Mar. 05 2022 | ||
10 | Mar. 12 2022 | |||
11 | Mar. 19 2022 | 5 | ||
12 | Mar. 26 2022 | |||
(1st Quarter) | 13 | Apr. 02 2022 | 25 | |
APRIL | 14 | Apr. 09 2022 | ||
15 | Apr. 16 2022 | 4/15 Good Friday | ||
16 | Apr. 23 2022 | 4 | ||
17 | Apr. 30 2022 | 19 | ||
MAY | 18 | May. 07 2022 | ||
19 | May. 14 2022 | 4 | ||
20 | May. 21 2022 | |||
21 | May. 28 2022 | 20 | ||
JUNE | 22 | Jun. 04 2022 | 5/30 Memorial day | |
23 | Jun. 11 2022 | |||
24 | Jun. 18 2022 | 5 | ||
25 | Jun. 25 2022 | |||
(2nd Quarter) | 26 | Jul. 02 2022 | 24 | |
JULY | 27 | Jul. 09 2022 7/4 for Independence Day | ||
28 | Jul. 16 2022 | 4 | ||
29 | Jul. 23 2022 | |||
30 | Jul. 30 2022 | 19 | ||
AUGUST | 31 | Aug. 06 2022 | ||
32 | Aug. 13 2022 | 4 | ||
33 | Aug. 20 2022 | |||
34 | Aug. 27 2022 | 20 | ||
SEPTEMBER | 35 | Sep. 03 2022 | ||
36 | Sep. 10 2022 | 9/5 Labor Day | ||
37 | Sep. 17 2022 | |||
38 | Sep. 24 2022 | 5 | ||
(3rd Quarter) | 39 | Oct. 01 2022 | 24 | |
OCTOBER | 40 | Oct. 08 2022 | ||
41 | Oct. 15 2022 | 10/10 Columbus day | ||
42 | Oct. 22 2022 | 4 | ||
43 | Oct. 29 2022 | 19 | ||
NOVEMBER | 44 | Nov. 05 2022 | ||
45 | Nov. 12 2022 | 4 | ||
46 | Nov. 19 2022 | |||
47 | Nov. 26 2022 | 11/24-25 Thanksgiving | 18 | |
DECEMBER | 48 | Dec. 03 2022 | ||
49 | Dec. 10 2022 | 5 | ||
50 | Dec. 17 2022 | |||
51 | Dec. 24 2022 | |||
(4th Quarter) | 52 | Dec. 31 2021 | 12/25 Christmas, 12/30 NY's Eve | 23 |
365 days | 250 |
@Hamdan1234 , Can you provide the calendar in excel or csv for 1-2 years?
also please check this video from Curbal
https://www.youtube.com/watch?v=JqVnqMLGWDY
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
104 | |
101 | |
79 | |
72 | |
64 |
User | Count |
---|---|
142 | |
108 | |
101 | |
81 | |
74 |