cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
diyannavarro Frequent Visitor
Frequent Visitor

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!
1 ACCEPTED SOLUTION

Accepted Solutions
Super User II
Super User II

Re: Power Query for Date If Statement

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.


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


MCSA: BI Reporting

View solution in original post

1 REPLY 1
Super User II
Super User II

Re: Power Query for Date If Statement

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.


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


MCSA: BI Reporting

View solution in original post

Helpful resources

Announcements
Coming Soon: T-Shirt Design Contest

Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors
Top Kudoed Authors