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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
dferry
Helper I
Helper I

Using DateTime.LocalNow IF Else

I am trying to use today's date to subtract from a column in power query that is a Due Date.  There could be a null value in the Due Date column.

My formula is if Date.From(DateTime.LocalNow()) - [DueDate] <=0 then "OnTime" else Date.From(DateTime.LocalNow()) - [DueDate]

It says No Syntax Errors have been detected but the results in the column are errors.  The error says Expression.Error: We cannot apply operator < to types Number and Duration.
Details:
Operator=<
Left=0
Right=847.00:00:00

2 ACCEPTED SOLUTIONS
BA_Pete
Super User
Super User

Hi @dferry ,

 

Try this instead:

if [DueDate] = null then null
else if Date.From(DateTime.LocalNow()) < [DueDate] then "OnTime"
else Text.From(
    Number.From(
        Duration.Days(Date.From(DateTime.LocalNow()) - [DueDate])
    )
)

 

You may need to fiddle with the final escape clause to get the exact output format you want, but the first two conditions should solve your isue.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

Kudos Pete.  That worked.  Thank you very much.

Doug

View solution in original post

2 REPLIES 2
BA_Pete
Super User
Super User

Hi @dferry ,

 

Try this instead:

if [DueDate] = null then null
else if Date.From(DateTime.LocalNow()) < [DueDate] then "OnTime"
else Text.From(
    Number.From(
        Duration.Days(Date.From(DateTime.LocalNow()) - [DueDate])
    )
)

 

You may need to fiddle with the final escape clause to get the exact output format you want, but the first two conditions should solve your isue.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Kudos Pete.  That worked.  Thank you very much.

Doug

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.