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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Super User
Super User

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!:
Power BI Cookbook Third Edition (Color)

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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