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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
bryn987
Helper I
Helper I

Custom column to find out in days/hours, how long it took between Created and Assigned on

I have a column called Created and a column called Assigned On - Date/Time, formated as date/time and I want to find out the average duration between those.  If Assigned On - Date/Time is blank, then use today's date.

 

I have this, but Im getting an operator error:

Expression.Error: We cannot apply operator - to types DateTime and Date.
Details:
Operator=-
Left=5/1/2023 8:33:52 AM
Right=5/1/2023

 

Here is my code

if [#"Assigned On - Date/Time"] <> null then Duration.From([#"Assigned On - Date/Time"] - [Created]) else Duration.From(DateTime.LocalNow() - [Created])

 

Any ideas?

1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

Hi @bryn987 ,

 

It seems Power Query has a problem with comparing the date/time column with the column formatted only as date.

 

Does it work with this one? 🙂

if [#"Assigned On - Date/Time"] <> null then Duration.From([#"Assigned On - Date/Time"] - DateTime.From([Created])) else Duration.From(DateTime.LocalNow() - DateTime.From([Created]))

 

Note, the DateTime.From function casts your date always as midnight, i.e. 1/5/2023 becomes 1/5/2023 00:00:00

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

5 REPLIES 5
bryn987
Helper I
Helper I

Everything is formatted as date/time.

 

tackytechtom your code is just pulling back the assigned date/time value

bryn987_0-1699643997601.png

 

Hi @bryn987 ,

 

Thats a weird one. If i use your initial query, it actually works well.

tackytechtom_0-1699645036058.png

 

do you get the error on all rows or just on a few single ones?

 

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

I had a typo and once I fixed that, your code worked.

 

Thank you!

Ahmedx
Super User
Super User

you first need to convert the date to datetime

Screenshot_5.png

tackytechtom
Super User
Super User

Hi @bryn987 ,

 

It seems Power Query has a problem with comparing the date/time column with the column formatted only as date.

 

Does it work with this one? 🙂

if [#"Assigned On - Date/Time"] <> null then Duration.From([#"Assigned On - Date/Time"] - DateTime.From([Created])) else Duration.From(DateTime.LocalNow() - DateTime.From([Created]))

 

Note, the DateTime.From function casts your date always as midnight, i.e. 1/5/2023 becomes 1/5/2023 00:00:00

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.