Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.
Check it out now!Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more
I have a master calendar table in a Power BI report that is based on a Power BI-created list of dates.
The problem is the dates do not extend far enough - only until June 30th 2022. I want to add dates into the future.
Any suggestions on how to do this?
This is the Advanced Editor code:
let
Source = List.Dates(StartDate, Length, #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}}),
StartDate = #date(2017, 7, 1),
Today = DateTime.Date(DateTime.LocalNow()),
Length = Duration.Days(Today-StartDate)+31,
#"Calendar View" = #"Changed Type",
#"Inserted Year" = Table.AddColumn(#"Calendar View", "Year", each Date.Year([Date]), Int64.Type),
#"Inserted Month Name" = Table.AddColumn(#"Inserted Year", "Month Name", each Date.MonthName([Date]), type text),
#"Inserted Month" = Table.AddColumn(#"Inserted Month Name", "Month", each Date.Month([Date]), Int64.Type),
#"Inserted Week of Year" = Table.AddColumn(#"Inserted Month", "Week of Year", each Date.WeekOfYear([Date]), Int64.Type),
YearMonth = Table.AddColumn(#"Inserted Week of Year", "YYMM", each ([Year]-2000)*100 + [Month]),
#"Changed Type1" = Table.TransformColumnTypes(#"YearMonth",{{"YYMM", Int64.Type}}),
#"Added MonthID" = Table.AddColumn(#"Changed Type1", "MonthID", each (Date.Year([Date]) - Date.Year(StartDate))*12 + Date.Month([Date])),
#"Changed Type2" = Table.TransformColumnTypes(#"Added MonthID",{{"MonthID", Int64.Type}}),
// =IF(MONTH(date)>6,YEAR(date)&"-"&YEAR(date)+1,YEAR(date)-1&"-"&YEAR(date))
FY = #"Changed Type2",
#"Added Custom" = Table.AddColumn(FY, "Custom", each if [Year]=2017 and [Month]<=6 then "FY1617"
else if [Year]=2017 and [Month]>=6 then "FY1718"
else if [Year]=2018 and [Month]<=6 then "FY1718"
else if [Year]=2018 and [Month]>=6 then "FY1819"
else if [Year]=2019 and [Month]<=6 then "FY1819"
else if [Year]=2019 and [Month]>=6 then "FY1920"
else if [Year]=2020 and [Month]<=6 then "FY1920"
else if [Year]=2020 and [Month]>=6 then "FY2021"
else if [Year]=2021 and [Month]<=6 then "FY2021"
else if [Year]=2021 and [Month]>=6 then "FY2122"
else if [Year]=2022 and [Month]<=6 then "FY2122"
else "FY2223"),
#"Renamed Columns1" = Table.RenameColumns(#"Added Custom",{{"Custom", "FY"}})
in
#"Renamed Columns1"
Solved! Go to Solution.
let
Startdate = #date(2020,1,1),
Span = 5,
Dates = Table.FromList(List.Dates(Startdate, Duration.TotalDays(Date.EndOfYear(Date.AddYears(Startdate,Span))-Startdate)+1,#duration(1,0,0,0)), Splitter.SplitByNothing(), {"Date"}),
FY = Table.AddColumn(Dates, "FY",
each let
yr = Number.Mod(Date.Year([Date]),100)
in if Date.Month([Date])>=6 then "FY" & Text.From(yr) & "-" & Text.From(yr+1) else "FY" & Text.From(yr-1) & "-" & Text.From(yr)
)
in
FY
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
let
Startdate = #date(2020,1,1),
Span = 5,
Dates = Table.FromList(List.Dates(Startdate, Duration.TotalDays(Date.EndOfYear(Date.AddYears(Startdate,Span))-Startdate)+1,#duration(1,0,0,0)), Splitter.SplitByNothing(), {"Date"}),
FY = Table.AddColumn(Dates, "FY",
each let
yr = Number.Mod(Date.Year([Date]),100)
in if Date.Month([Date])>=6 then "FY" & Text.From(yr) & "-" & Text.From(yr+1) else "FY" & Text.From(yr-1) & "-" & Text.From(yr)
)
in
FY
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
@Anonymous
here a solution I found helpful. It is verly likely there will be solution more efficient than mine.
In any case you can set date by Manage Parameters.
/* StartingYear come from a parameter with data input = "mm/dd/yyyy*/
/* StartingYear should always start from January 1t */
StartDate = Date.From(StartingYear),
/* EndingYear come from a parameter with data input = "mm/dd/yyyy */
/* EndigYear should always ending at December, 31st */
EndDate = Date.From(EndingYear),
/*----------------------------------------------------------------------------------------------------------------------------*/
Regards