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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Duration time

 

I have time stamp data I'm working with. I have data I get in a excel file that I'm uploading to Power BI that has Production Hours field. This field is the amount of time it took to do a task. I have it as hh:mm:ss in excel so ex) 7:40:00 or 0:20:00 means they worked for 7 hours and 40 mins or 20 min. When I bring this into Power BI it turns it into a time. So example becomes 7:40:00 AM and 12:20:00 AM

How can I turn this into a duration and not a time ?

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

We can just add two steps to get the duration time if your excel is format as hh:mm:ss:

 

[Duration] - #datetime(1899,12,31,0,0,0)

9.PNG10.PNG

 

Then just delete the origin column and rename the new column

 

11.PNG

 

The full version M Query is here:

 

let
    Source = Excel.Workbook(File.Contents("D:\Test\2019-10-08\Duration-time.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    #"Added Custom" = Table.AddColumn(#"Promoted Headers", "Custom", each [Duration] - #datetime(1899,12,31,0,0,0)),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", type duration}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Duration"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Duration"}})
in
    #"Renamed Columns"

you can use time to show in the field, or keep the origin duration number (the total day)

 

12.PNG


BTW, pbix and excel as attached.

 

Best regards,

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

9 REPLIES 9
v-lid-msft
Community Support
Community Support

Hi @Anonymous ,


How about the result after you follow the suggestions mentioned in my original post?Could you please provide more details about it If it doesn't meet your requirement?

 

Best regards,

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ChrisMendoza
Resident Rockstar
Resident Rockstar

@Anonymous -

Remove the Applied Step(s) in Power Query that changed the Data Type to 'Time'? It will be a Text value though so I am unsure if that is your desired result.






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Anonymous
Not applicable

I just tried to do this and this changed it to 12/31/1899 7:40:00 AM. The desired outcome would be to only have 7:40:00 

Hi @Anonymous ,

 

We can just add two steps to get the duration time if your excel is format as hh:mm:ss:

 

[Duration] - #datetime(1899,12,31,0,0,0)

9.PNG10.PNG

 

Then just delete the origin column and rename the new column

 

11.PNG

 

The full version M Query is here:

 

let
    Source = Excel.Workbook(File.Contents("D:\Test\2019-10-08\Duration-time.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    #"Added Custom" = Table.AddColumn(#"Promoted Headers", "Custom", each [Duration] - #datetime(1899,12,31,0,0,0)),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", type duration}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Duration"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Duration"}})
in
    #"Renamed Columns"

you can use time to show in the field, or keep the origin duration number (the total day)

 

12.PNG


BTW, pbix and excel as attached.

 

Best regards,

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

So Excel already converted it to 'Time'; I'm guessing the formula bar shows something like 7:40:00 AM already but with custom formatting it displays as 7:40:00 in the cell? Do you have the flexibilty to do the calculation within Power Query rather than in your Excel file for duration? Another option is just to remove the date, delimit by space, then convert to Text the visual representation of duration.

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



@Anonymous change data type to duration in power query in Power BI and rest calculations will be super easy. No need to do that in Excel.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

ah ok it worked now when I changed to duration ! Thanks ! Another question for items that were less then a hour so 0:20:00 are displaying as 12:20:00 with the duration conversion. Is there a DAX formula to change the 12 to 0 ? 



 

@Anonymous well if you use duration function to get minutes, it will give you 20 minutes, not sure if that is wht you are asking.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@Anonymous convert your time column data type to duration which you can do by clicking the data type on column header. Form here you can add custom column for total hours, total minutes or Hours and Mintures. basically all duration functions available in power query



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.