Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hi All,
I am new to Power Bi and this is a problem im having:
I want to calculate the duration between two dates columns:
| First Book On | Last Book Off |
| 01/01/2020 20:20 | 02/01/2020 00:15 |
| 04/01/2020 20:06 | 04/01/2020 22:36 |
| 05/01/2020 19:59 | 05/01/2020 23:08 |
| 06/01/2020 23:20 | 07/01/2020 00:11 |
| 07/01/2020 21:17 | 07/01/2020 23:10 |
| 09/01/2020 17:53 | 09/01/2020 23:57 |
I used the following code to calculate the duration below:
Time = VAR Duration = DATEDIFF([First Book On], [Last Book Off], SECOND ) VAR Hours = INT ( Duration / 3600) VAR Minutes = INT ( MOD( Duration - ( Hours * 3600 ),3600 ) / 60) VAR Seconds = ROUNDUP(MOD ( MOD( Duration - ( Hours * 3600 ),3600 ), 60 ),0) VAR H = IF ( LEN ( Hours ) = 1, CONCATENATE ( "0", Hours ), CONCATENATE ( "", Hours ) ) VAR M = IF ( LEN ( Minutes ) = 1, CONCATENATE ( "0", Minutes ), CONCATENATE ( "", Minutes ) ) VAR S = IF ( LEN ( Seconds ) = 1, CONCATENATE ( "0", Seconds ), CONCATENATE ( "", Seconds ) ) RETURN CONCATENATE ( H, CONCATENATE ( ":", CONCATENATE ( M, CONCATENATE ( ":", S ) ) ) ) |
See if these help:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Chelsie-Eiden-s-Duration/m-p/793639#M389
https://community.powerbi.com/t5/Quick-Measures-Gallery/Duration-to-Seconds-Converter/m-p/342279#M92
Did you set your Time column to a data type of integer? You would need it set to a type of text. Otherwise, see the first article to see how you can leave it in a certain integer format and display it as a duration.
"Did you set your Time column to a data type of integer? You would need it set to a type of text. Otherwise, see the first article to see how you can leave it in a certain integer format and display it as a duration."
Yes I set the time column data type to Text but I get negative numbers on some rows:
| First Book On | Last Book Off | Duration |
| 01/01/2020 20:20 | 02/01/2020 00:15 | -21:55:00 |
| 04/01/2020 20:06 | 04/01/2020 22:36 | 02:30:00 |
| 05/01/2020 19:59 | 05/01/2020 23:08 | 03:09:00 |
| 06/01/2020 23:20 | 07/01/2020 00:11 | -20:32:00 |
| 07/01/2020 21:17 | 07/01/2020 23:10 | 02:36:00 |
| 09/01/2020 17:53 | 09/01/2020 23:57 | 03:19:00 |
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 5 | |
| 5 | |
| 4 |
| User | Count |
|---|---|
| 25 | |
| 16 | |
| 9 | |
| 8 | |
| 8 |