Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Alex_Bartlett
Frequent Visitor

Error will DateTime.LocalNow due to blanks

Morning all,

 

I am having an issue with trying to add a column to track current employees on a report.

 

To explain what I am trying to achieve, I want to return "true" or "false" for employees based on their contract end date.

Any end dates that are blank/null or in the future would be true while in the past are false.

 

I have tried to get this with the below but am getting errors with the date if statement (I think due to null values).

 

Table.AddColumn(#"Added Custom", if[ContractEndDate] = null or [ContractEndDate] > DateTime.LocalNow then "True" else "False")

 

If I attempt to use the below on its own I get the error "Expression.Error: We cannot apply operator < to types Function and Null."

Table.AddColumn(#"Added Custom", if [ContractEndDate] > DateTime.LocalNow then "True" else "False")

 

Any ideas how I can fix this? 

 

Many thanks,

Alex

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Replace DateTime.LocalNow with

Date.From(DateTime.LocalNow())

Also just this much is enough (You hadn't supplied column name in your Table.AddColumn. I have named it Result)

 

= Table.AddColumn(#"Added Custom", "Result", each [ContractEndDate] = null or [ContractEndDate] > Date.From(DateTime.LocalNow()))

 

 

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Super User
Super User

Replace DateTime.LocalNow with

Date.From(DateTime.LocalNow())

Also just this much is enough (You hadn't supplied column name in your Table.AddColumn. I have named it Result)

 

= Table.AddColumn(#"Added Custom", "Result", each [ContractEndDate] = null or [ContractEndDate] > Date.From(DateTime.LocalNow()))

 

 

Thank you for your help! 🙂

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors