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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

DateDiff is calculating the HOURS wrongly

Capture.PNG

 

 

I am trying to calculate the DATEDIFF in hours. But I am getting wrong values. Please see attached screenshot.

 

The first entry is same dates and the total time difference is 14 minutes. But I am getting 1 for the hour calculation. Why?

 

Is there any way to show the time difference between these two date time values like 00:14 and 2817:00?

 

Please help.

 

 

1 ACCEPTED SOLUTION
Nolock
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

it works correct but you expect something else that it actually does.

According to DATEDIFF func definition the return value is "The count of interval boundaries crossed between two dates."

Capture2.PNG

PowerBI doesn't have a duration data type, it means you have to calculate everything by yourself.
Create a diff of minutes and then divide it by 60 and you'll get your expected result.

Diff2 =
VAR DiffInMinutes =
    DATEDIFF ( Table1[Start]; Table1[End]; MINUTE )
VAR DiffInHours =
    QUOTIENT ( DiffInMinutes; 60 )
VAR ModuloDiffInMinutes =
    MOD ( DiffInMinutes; 60 )
VAR Result =
    FORMAT ( DiffInHours; "00" ) & ":"
        & FORMAT ( ModuloDiffInMinutes; "00" )
RETURN
    Result

 

View solution in original post

3 REPLIES 3
Nolock
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

it works correct but you expect something else that it actually does.

According to DATEDIFF func definition the return value is "The count of interval boundaries crossed between two dates."

Capture2.PNG

PowerBI doesn't have a duration data type, it means you have to calculate everything by yourself.
Create a diff of minutes and then divide it by 60 and you'll get your expected result.

Diff2 =
VAR DiffInMinutes =
    DATEDIFF ( Table1[Start]; Table1[End]; MINUTE )
VAR DiffInHours =
    QUOTIENT ( DiffInMinutes; 60 )
VAR ModuloDiffInMinutes =
    MOD ( DiffInMinutes; 60 )
VAR Result =
    FORMAT ( DiffInHours; "00" ) & ":"
        & FORMAT ( ModuloDiffInMinutes; "00" )
RETURN
    Result

 

Anonymous
Not applicable

Thank you for your response and solution. Is it possible to exclude the weekends in the suggested calculation please.

 

Kindly let me know..

Hi @Anonymous,

 

yes, it is possible but please mark this ticket as a solution.
And then open a new one with your next question regarding excluding weekends. If you mention me in the new ticket, I will be notified and can help you immediately further.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.