cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
edhans New Contributor
New Contributor

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.

View solution in original post

1 REPLY 1
edhans New Contributor
New Contributor

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.

View solution in original post

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 6 members 991 guests
Please welcome our newest community members: