jps I guess it may also be dependant on what you want this for, however, you could consider using the Period Slicer M Code (provided sometime ago on the EDNA pages, will look it up).
But M Code for this is below (hidden of ‘periods’ in the Code below and shown in the attached pbix for your information
dateslicer - DH.pbix (162.5 KB)
let
TodaysDate = Date.From(DateTimeZone.FixedUtcNow()),
Ranges = {
{“Current YTD”, Date.From(Date.StartOfYear(TodaysDate)), TodaysDate, 1}
// {“Last 3 Months”, Date.AddMonths(TodaysDate, -3), TodaysDate, 2},
// {“Last 6 Months”, Date.AddMonths(TodaysDate, -6), TodaysDate, 3},
// {“Last 9 Months”, Date.AddMonths(TodaysDate, -9), TodaysDate, 4},
// {“Last 12 Months”, Date.AddYears(TodaysDate, -1), TodaysDate, 5},
// {“Last 24 Months”, Date.AddYears(TodaysDate, -2), TodaysDate, 6},
// {“Last 36 Months”, Date.AddYears(TodaysDate, -3), TodaysDate, 7}
},
fxCreatePeriodTabe = ( PeriodName as text, StartDate as date, EndDate as date, SortOrder as number ) as table =>
let
DayCount = Duration.Days(EndDate-StartDate)+1,
DateList = List.Dates(StartDate,DayCount,#duration(1,0,0,0)),
AddPeriodName = List.Transform(DateList, each {PeriodName,_,SortOrder}),
CreateTable = #table( type table[Period=text, Date=date, Sort=number], AddPeriodName)
in
CreateTable,
GetTables = List.Transform(Ranges, each fxCreatePeriodTabe(_{0}, _{1}, _{2}, _{3})),
Output = Table.Combine(GetTables)
in
Output
Hope this helps?
David Hampson