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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Cannot Convert value 'xx:xx:xx' of type Text to type Integer

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 OnLast Book Off
01/01/2020 20:2002/01/2020 00:15
04/01/2020 20:0604/01/2020 22:36
05/01/2020 19:5905/01/2020 23:08
06/01/2020 23:2007/01/2020 00:11
07/01/2020 21:1707/01/2020 23:10
09/01/2020 17:5309/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 ) ) )
)
 
After running the code, I get #ERROR in Time column and received an error message: 
Cannot Convert value 'hh:mm:ss' of type Text to type Integer.
 
How can I solve this?
3 REPLIES 3
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

Try this column on Power Query:

 

Capture.PNG

 

If you consider it as a solution, please mark as a solution and kudos.

Ricardo



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Greg_Deckler
Community Champion
Community Champion

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.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

"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 OnLast Book OffDuration
01/01/2020 20:2002/01/2020 00:15-21:55:00
04/01/2020 20:0604/01/2020 22:3602:30:00
05/01/2020 19:5905/01/2020 23:0803:09:00
06/01/2020 23:2007/01/2020 00:11-20:32:00
07/01/2020 21:1707/01/2020 23:1002:36:00
09/01/2020 17:5309/01/2020 23:5703:19:00

 

 

 
 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.