Forum Discussion

Alex_Bartlett's avatar
Alex_Bartlett
Frequent Visitor
4 years ago
Solved

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

  • 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()))

     

     

2 Replies

  • Vijay_A_Verma's avatar
    Vijay_A_Verma
    Most Valuable Professional

    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()))