Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Date Check in year to date last year

if Date.IsInYearToDate(Date.AddYears([Date], 2)) then "Yes" else if Date.IsInYearToDate(Date.AddYears([Date], 1)) then "Yes" else if Date.IsInYearToDate([Date]) then "Yes" else "No"   ...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi,

    Thanks for the solutions rajasaadk_98  and PhilipTreacy offered, and i want to offer some more information for user to refer to.

    hello Anonymous , you can create a custom column and input the following.

    let _today=Date.AddDays(Date.From(DateTime.LocalNow()),-1),
    _twoyearsago=Date.AddYears(_today,-2),
    _oneyearsago=Date.AddYears(_today,-1),
    _startmonth=Date.StartOfYear(_today),
    _starttwoyears=Date.StartOfYear(_twoyearsago),
    _startoneyear=Date.StartOfYear(_oneyearsago)
    in if ([Date]>=_starttwoyears and [Date]<=_twoyearsago) or ([Date]>=_startoneyear and [Date]<=_oneyearsago) or ([Date]>=_startmonth and [Date]<=_today) then "Yes" else "No"

    e.g today is 10/16/2024 

    Ouput

    Then filter it, it can work, and you can refer to the following whole code.

    let
    
        Source = List.Dates(#date(2019,1,1),Duration.Days(Date.From(DateTime.LocalNow())-#date(2019,1,1)),#duration(1,0,0,0)),
    
        #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), {"Date"}, null, ExtraValues.Error),
        #"Added Custom1" = Table.AddColumn(#"Converted to Table", "Custom", each let _today=Date.AddDays(Date.From(DateTime.LocalNow()),-1),
    _twoyearsago=Date.AddYears(_today,-2),
    _oneyearsago=Date.AddYears(_today,-1),
    _startmonth=Date.StartOfYear(_today),
    _starttwoyears=Date.StartOfYear(_twoyearsago),
    _startoneyear=Date.StartOfYear(_oneyearsago)
    in if ([Date]>=_starttwoyears and [Date]<=_twoyearsago) or ([Date]>=_startoneyear and [Date]<=_oneyearsago) or ([Date]>=_startmonth and [Date]<=_today) then "Yes" else "No"),
        #"Filtered Rows" = Table.SelectRows(#"Added Custom1", each ([Custom] = "Yes"))
    in
        #"Filtered Rows"

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.