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
Olifer
Frequent Visitor

Calculating time difference does not deliver the expected result

Dear community,

 

I need to calculate the time difference between a column named "time_val" (formatted as date/time) as provided in the image below and "1/1/1970 0:00:00". The result should be provided in hours. 

 Input DataInput Data

 

So I created a new column and tried to calculate the time difference with the following expression: 

duration = DATEDIFF(DateValue("1/1/1970"),SomeTable[time_val].[Date],HOUR)

 

Unfortunately, this only provides the duration in multiples of 24, so it basically seems to calculate the days and multiply the result with 24. What I would need, however, is the exact number of hours.

 

To give an example: For an entry "01.01.1970 14:20:00" I would expect a response of 14 (hours). What I get, however, is 0.

 

I'd highly appreciate any help.

 

Thanks and best regards

Oliver

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

@Olifer 

Don't use the .date extension on the field.  That invokes the hidden auto time intelligence date field.  Try this.

duration = DATEDIFF(DateValue("1/1/1970"),SomeTable[time_val],HOUR)

 

View solution in original post

2 REPLIES 2
jdbuchanan71
Super User
Super User

@Olifer 

Don't use the .date extension on the field.  That invokes the hidden auto time intelligence date field.  Try this.

duration = DATEDIFF(DateValue("1/1/1970"),SomeTable[time_val],HOUR)

 

@jdbuchanan71 

 

that did the trick! Thanks a lot for your quick support!

 

Best regards

Oliver

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.