Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Calendar table is not updating correctly

I created a calendar table with M to join all my tables by that one because I need to filter by date all my visualizations. What I need is a calendar table which starter date begins at 2016,1,1 and it ends with current date becuase my data updates everyday. To returns the current date I used this code:

 

 

DateTime.Date(DateTime.LocalNow())

 

 

When I only use this code It returns me the current date, but when use it all together returns me the date before, e.g. if my current date is 06/03/2020, when I update my calendar table and I sort in descending It returns me as last data 05/03/2020. 

This is my entire 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(2016, 1, 1),
    Today = DateTime.Date(DateTime.LocalNow()),
    Length = Duration.Days(Today - StartDate),
    Custom1 = #"Changed Type",
    #"Inserted Year" = Table.AddColumn(Custom1, "Year", each Date.Year([Date]), Int64.Type),
    #"Inserted Month Name" = Table.AddColumn(#"Inserted Year", "Month Name", each Date.MonthName([Date]), type text),
    #"Inserted Day Name" = Table.AddColumn(#"Inserted Month Name", "Day Name", each Date.DayOfWeekName([Date]), type text),
    #"Inserted Day of Week" = Table.AddColumn(#"Inserted Day Name", "Day of Week", each Date.DayOfWeek([Date])+1, Int64.Type),
    #"Added Custom1" = Table.AddColumn(#"Inserted Day of Week", "MonthID", each Date.Month([Date])),
    #"Changed Type2" = Table.TransformColumnTypes(#"Added Custom1",{{"MonthID", Int64.Type}}),
    #"Filas ordenadas" = Table.Sort(#"Changed Type2",{{"Date", Order.Descending}}),
    #"Columna duplicada" = Table.DuplicateColumn(#"Filas ordenadas", "Date", "Date - Copia"),
    #"Semana del mes calculada" = Table.TransformColumns(#"Columna duplicada",{{"Date - Copia", Date.WeekOfMonth, Int64.Type}}),
    #"Columnas con nombre cambiado" = Table.RenameColumns(#"Semana del mes calculada",{{"Date - Copia", "Semana del mes"}})
in
    #"Columnas con nombre cambiado"

 

 

I've just updated my table and this is my result: 

 

I've checked the systems date and It's Ok. 

This is the result when I just use DateTime.LocalNow():

 

I hope you can help me! 

  • Hi Anonymous 

     

    You need to add 1 to your length.

    Length = Duration.Days(Today - StartDate) +1,
    Best Regards,
    Mariusz

    If this post helps, then please consider Accepting it as the solution.

    Please feel free to connect with me.
    LinkedIn

     

     

2 Replies

  • Mariusz's avatar
    Mariusz
    Community Champion

    Hi Anonymous 

     

    You need to add 1 to your length.

    Length = Duration.Days(Today - StartDate) +1,
    Best Regards,
    Mariusz

    If this post helps, then please consider Accepting it as the solution.

    Please feel free to connect with me.
    LinkedIn

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you, I also found this solution 

      Today= Date.AddDays(Date.From(DateTime.LocalNow()),1),