Forum Discussion

diyannavarro's avatar
diyannavarro
Frequent Visitor
7 years ago
Solved

Power Query for Date If Statement

I have two columns in my date which is approval date and expiry date, and I need to apply this condition using M query:

 

If Approval date <= Current Date and Expiry Date >=Current Date then "Active" else "Expired"

 

I've tried this query in the Power BI desktop and is running but when I run it in the Power BI Data flows it gives me an error:

#"Added Custom" = Table.AddColumn(#"Inserted conditional column 1", "STATUS", each if [EXPIRY DATE] >= DateTime.LocalNow() and [RAW APPROVED DATE] <= DateTime.LocalNow() then "ACTIVE" else "EXPIRED")
 
Thanks!
  • Try wrapping Date.TimeLocalNow() with DateTime.Date(), so DateTime.Date(DateTime.LocaNow())

    DateTime.LocalNow will returns the date and time, and you may get comparison errors if you are comparing strictly to a date. DateTime.Date will strip out the time component.

1 Reply

  • edhans's avatar
    edhans
    Community Champion

    Try wrapping Date.TimeLocalNow() with DateTime.Date(), so DateTime.Date(DateTime.LocaNow())

    DateTime.LocalNow will returns the date and time, and you may get comparison errors if you are comparing strictly to a date. DateTime.Date will strip out the time component.