Forum Discussion

AnandNamburi's avatar
AnandNamburi
Icon for Helper III rankHelper III
5 years ago
Solved

How limit the below code to display till current date only.

Hi All,

I'm using the below code to get the Time Dim.

But my the dates are getting more than what we are(>current date/today).

can any one suggest how we can fine tune the below code so that it shoud not exceed the current year(It shoud be dynamic).

Logic:

let
StartDate = #date(2017,04,01),
YearsToGenerate=20,
BaseList=List.Dates( StartDate,
YearsToGenerate*366,
#duration(1,0,0,0)
),
#"Converted to Table" = Table.FromList(BaseList, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in
#"Converted to Table"

 

 

Thanks,

Anand

  • AnandNamburi Try this code

     

    let
    StartDate = #date(2017,04,01),
    Today = Date.From(DateTime.LocalNow()),
    GetDateCount = Duration.Days(Today - StartDate) + 1,
    BaseList=List.Dates( StartDate,
    GetDateCount,
    #duration(1,0,0,0)
    ),
    #"Converted to Table" = Table.FromList(BaseList, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
    in
    #"Converted to Table"

2 Replies

  • AnandNamburi , I think you can use this in place of days you are giving in List.Dates

    Duration.Days(DateTime.LocalNow() - [StartDate])

     

  • AnandNamburi Try this code

     

    let
    StartDate = #date(2017,04,01),
    Today = Date.From(DateTime.LocalNow()),
    GetDateCount = Duration.Days(Today - StartDate) + 1,
    BaseList=List.Dates( StartDate,
    GetDateCount,
    #duration(1,0,0,0)
    ),
    #"Converted to Table" = Table.FromList(BaseList, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
    in
    #"Converted to Table"