Forum Discussion

commited2020's avatar
commited2020
Frequent Visitor
3 years ago
Solved

Date Error in M query editor

Hello i keep getting this message: Expression.Error: We cannot apply operator - to types DateTime and Date. Details: Operator=- Left=1/1/2024 12:00:00 πμ Right=1/1/2016 Here is the code at M qu...
  • tt_and's avatar
    tt_and
    3 years ago

    Yes, the answer is in this line which is dynamic for both start and end (one year back in time (-1), and end of this year:

     

     Source = {Number.From(#date(Date.Year(DateTime.LocalNow()) - 1,01,01))..Number.From(#date(Date.Year(DateTime.LocalNow()),12,31))}

     

    You can set it relative to both start or end (-1 is -1 year).

    Or with fixed start and dynamic end:

     Source = {Number.From(#date(2016,01,01))..Number.From(#date(Date.Year(DateTime.LocalNow()),12,31))}

     Or with fixed start and end: 

     Source = {Number.From(#date(2016,01,01))..Number.From(#date(2023,12,31))}