Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Anonymous
Not applicable

Extending Date List Values

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"

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

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!

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

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!

gpiero
Skilled Sharer
Skilled Sharer

@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

If I can...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.