0% found this document useful (0 votes)
5 views1 page

CALENDAR

This document outlines a Power Query M script that generates a calendar table starting from January 1, 2019, and extending three months from the current date. It includes various transformations to create date-related columns such as DateKey, Year, Quarter, Month name, and Day of the week. The final output is a table that merges fiscal year and quarter information for sorting purposes.

Uploaded by

Rocio Cisterna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

CALENDAR

This document outlines a Power Query M script that generates a calendar table starting from January 1, 2019, and extending three months from the current date. It includes various transformations to create date-related columns such as DateKey, Year, Quarter, Month name, and Day of the week. The final output is a table that merges fiscal year and quarter information for sorting purposes.

Uploaded by

Rocio Cisterna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

let

startDate = #date(2019, 1, 1),


// Edit the number in this step to change the number of months after today for the
last day of the Calendar table.
endDate = Date.AddMonths(Date.From(DateTime.LocalNow()),3),
Dates = List.Dates(startDate, Duration.Days(endDate - startDate), #duration
(1,0,0,0)),
#"Converted to Table" = Table.FromList(Dates, 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 DateKey" = Table.AddColumn(#"Changed Type", "DateKey", each
Date.ToText([Date],"yyyyMMdd"), type text),
#"Inserted Year" = Table.AddColumn(#"Inserted DateKey", "Year", each
Date.Year([Date]), Int64.Type),
#"Inserted Quarter" = Table.AddColumn(#"Inserted Year", "Quarter", each
Date.QuarterOfYear([Date]), Int64.Type),
#"Inserted FY Quarters" = Table.AddColumn(#"Inserted Quarter", "FY Quarter", each
if [Quarter] = 1 then "4" else if [Quarter] = 2 then "1" else if [Quarter] = 3 then
"2" else "3", type text),
#"Inserted Month Name" = Table.AddColumn(#"Inserted FY Quarters", "Month name",
each Date.MonthName([Date]), type text),
#"Inserted Month" = Table.AddColumn(#"Inserted Month Name", "Month number", each
Date.Month([Date]), Int64.Type),
#"Inserted Day of Month" = Table.AddColumn(#"Inserted Month", "Day of month",
each Date.Day([Date]), Int64.Type),
#"Inserted Day of Year" = Table.AddColumn(#"Inserted Day of Month", "Day of
Year", each Date.DayOfYear([Date]), Int64.Type),
#"Inserted Day of Week" = Table.AddColumn(#"Inserted Day of Year", "Day of
Week", each Date.DayOfWeek([Date]), Int64.Type),
#"Inserted Day Name" = Table.AddColumn(#"Inserted Day of Week", "Day name",
each Date.DayOfWeekName([Date]), type text),
// In Week functions
// 0 represents Sunday start
// 1 represents Monday start
// 2 represents Tuesday start
#"Inserted Week of Year" = Table.AddColumn(#"Inserted Day Name", "Week of
Year", each Date.WeekOfYear([Date],1), Int64.Type),
#"Inserted Week of Month" = Table.AddColumn(#"Inserted Week of Year", "Week of
Month", each Date.WeekOfMonth([Date],1), Int64.Type),
#"Inserted FY start" = Table.AddColumn(#"Inserted Week of Month", "FY starts",
each [Year] + (if [Month number] > 3 then 0 else -1), type number),
#"Inserted FY" = Table.AddColumn(#"Inserted FY start", "FY", each Text.From([FY
starts]) & "/" & Text.From([FY starts] + 1), type text),
#"Inserted FY and Quarter" = Table.AddColumn(#"Inserted FY", "FY and Quarter",
each Text.Combine({Text.From([FY starts], "en-NZ"), [FY Quarter]}, " Q"), type
text),
#"Inserted Merged Column" = Table.AddColumn(#"Inserted FY and Quarter", "FY and
Quarter Sort", each Text.Combine({Text.From([FY starts]), [FY Quarter]}, ""), type
text)
in
#"Inserted Merged Column"

You might also like