Forum Discussion
DateDiff is calculating the HOURS wrongly
- 7 years ago
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."
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
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."
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
- Anonymous7 years agoNot applicable
Thank you for your response and solution. Is it possible to exclude the weekends in the suggested calculation please.
Kindly let me know..
- Nolock7 years agoResident Rockstar
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.