Forum Discussion
Anonymous
3 years agoNot applicable
Fiscal Calendar Date Table
Hi All! I am looking for the most efficient way to create a Fiscal Calendar Date Table (Fiscal Year starting in July). I'm looking for the calendar to not have a specific beginning date (min) o...
- 3 years ago
Please try out this approach that dynamically gets the start and end dates dynamically from your fact table. The first is the M/Power Query version (note this may cause performance problems as it will effectively load your fact table a second time to get these dates). The 2nd is the DAX version of same.
let FactDates = List.Buffer(List.Distinct(FactQuery[DateColumn])), StartDate = List.Min(FactDates), EndDate = List.Max (FactDates), DateList = List.Dates(StartDate, Number.From(EndDate - StartDate)+1, #duration(1,0,0,0)), InitialTable = Table.FromColumns({DateList}, {"Date"}), #"Changed Type" = Table.TransformColumnTypes(InitialTable,{{"Date", type date}}), AddFY = Table.AddColumn(#"Changed Type", "FY", each Date.Year(Date.AddMonths([Date], 6))), AddFQ = Table.AddColumn(AddFY, "FQ", each Date.QuarterOfYear(Date.AddMonths([Date], 6))), AddFM = Table.AddColumn(AddFQ, "FM", each Date.Month(Date.AddMonths([Date], 6))), #"Added Custom" = Table.AddColumn(AddFM, "FW", each let FYstart = #date([FY]-1, 7, 1), result = Number.RoundUp((Duration.TotalDays([Date] - FYstart)+1)/7, 0) in result), #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"FY", Int64.Type}, {"FQ", Int64.Type}, {"FM", Int64.Type}, {"FW", Int64.Type}}) in #"Changed Type1"FiscalDates = ADDCOLUMNS ( CALENDAR ( MIN ( Sales[SaleDate] ), MAX ( Sales[SaleDate] ) ), "FY", YEAR ( EOMONTH ( [Date], 6 ) ), "FQ", QUARTER ( EOMONTH ( [Date], 6 ) ), "FM", MONTH ( EOMONTH ( [Date], 6 ) ), "FW", ROUNDUP ( ( INT ( [Date] - DATE ( YEAR ( EOMONTH ( [Date], 6 ) ) - 1, 7, 1 ) ) + 1 ) / 7, 0 ) )Pat
ppm1
Solution Sage
3 years agoPlease try out this approach that dynamically gets the start and end dates dynamically from your fact table. The first is the M/Power Query version (note this may cause performance problems as it will effectively load your fact table a second time to get these dates). The 2nd is the DAX version of same.
let
FactDates = List.Buffer(List.Distinct(FactQuery[DateColumn])),
StartDate = List.Min(FactDates),
EndDate = List.Max (FactDates),
DateList = List.Dates(StartDate, Number.From(EndDate - StartDate)+1, #duration(1,0,0,0)),
InitialTable = Table.FromColumns({DateList}, {"Date"}),
#"Changed Type" = Table.TransformColumnTypes(InitialTable,{{"Date", type date}}),
AddFY = Table.AddColumn(#"Changed Type", "FY", each Date.Year(Date.AddMonths([Date], 6))),
AddFQ = Table.AddColumn(AddFY, "FQ", each Date.QuarterOfYear(Date.AddMonths([Date], 6))),
AddFM = Table.AddColumn(AddFQ, "FM", each Date.Month(Date.AddMonths([Date], 6))),
#"Added Custom" = Table.AddColumn(AddFM, "FW", each let
FYstart = #date([FY]-1, 7, 1),
result = Number.RoundUp((Duration.TotalDays([Date] - FYstart)+1)/7, 0)
in
result),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"FY", Int64.Type}, {"FQ", Int64.Type}, {"FM", Int64.Type}, {"FW", Int64.Type}})
in
#"Changed Type1"
FiscalDates =
ADDCOLUMNS (
CALENDAR ( MIN ( Sales[SaleDate] ), MAX ( Sales[SaleDate] ) ),
"FY", YEAR ( EOMONTH ( [Date], 6 ) ),
"FQ", QUARTER ( EOMONTH ( [Date], 6 ) ),
"FM", MONTH ( EOMONTH ( [Date], 6 ) ),
"FW",
ROUNDUP (
(
INT ( [Date] - DATE ( YEAR ( EOMONTH ( [Date], 6 ) ) - 1, 7, 1 ) ) + 1
) / 7,
0
)
)Pat
Anonymous
3 years agoNot applicable
ppm1 - It worked! Thank you!! 🙂