Forum Discussion

Havard's avatar
Havard
Frequent Visitor
5 years ago
Solved

Find if a date from API is YTD or LYTD

I'm really new to this. I can't find how to do what's marked with BOLD. I would be very happy if anyone could help med with this:   if [postingDate] >= #date(ThisYear, 1, 1) and [postingDate] <= #d...
  • edhans's avatar
    edhans
    5 years ago

    That is how you do it. The clean code would be something like this Havard 

    let 
       varToday = Date.From(DateTimeZone.FixedUtcNow())
    in
    
    if [postingDate] >= Date.StartOfYear(varToday) and [postingDate] <= varToday
    
    then "YTD"
    
    else if [postingDate] >= Date.AddYears(varToday,-1) and [postingDate] <= Date.AddYears(varToday,-1)
    
    then "LYTD"