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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
fstupot
Helper II
Helper II

powerbi converting duration time hh:mm:ss into date hh:mm:ss

hi guys,

 

please can you help.

 

i have an excel data source that shows duration in hh:mm:ss when it gets pulled into powerbi it adds date and also changes the time.

 

i just want it to leave it alone!

 

how do i stop powerbi converting it, or convert it back?

 

whenever i try changing the format back to hh:mm it gives me the wrong duration

 

please help 

 

Lucy x

1 ACCEPTED SOLUTION

Thanks for the data @fstupot 

 

i'm not entirely sure where your total time is calculated, so if @Nathaniel_C  's solution helps, great. if not, you can try split column by delimiter to convert your duration columns into numeric columns

 

paste the below code into advanced editor to see what i mean

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZLLbhNRDIZfJZp15fpyrl4iAQuQQArhoiqqojIREYVFCQveHtsnNCPSRaWRxmP7+Hzz+7+5mV68KvJ583G6mtbH3X5/+/Zw921/mO+/rt69X1sW+ZrompFxhU0xW4rzY4qSClmqVk1FsXs1KXfNYqEQRD8rilLxsIGU0SSoOZ+a2N7ZD6dcoUzbq+CqLzdvzlzz/P0fkpyRqnL9Dymr+Cgi0mQgPltYpdiXd3YIklM1QoTcnAAVy/iflKBRlHx6oQZ9QbV5jlp2QXAs0WTgtGJvjdEmRBJFGtqkkKurNSavikDxFJm8PM4yQowtIVdBSAuw8xpf7w73858ndmiCyYVgiH4JZ8dij6W7YJnGfoIltq/kOAWShCx20PboIG00UfxBwwR1gfXpWe6yBaULd6Ff1Ey3ZI9XqxoIBRiDeMoOkknmelQI37G7Yqzbmqqnagp3deAF15dHrvXvh/3ubl59eJh3xx/zz+OvC9mIn4YjFrcNu4Ms5HZSswMOczkLe2gaOVIz7/fRXxrUkE0kRLTdTtvtXw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Vehicle = _t, Group = _t, Start = _t, End = _t, #"Total Time" = _t, Moving = _t, #"% Moving" = _t, Idling = _t, #"% Idling" = _t, Stopped = _t, #"% Stopped" = _t, Stops = _t, Miles = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Vehicle", type text}, {"Group", type text}, {"Start", type datetime}, {"End", type datetime}, {"Total Time", type text}, {"Moving", type text}, {"% Moving", type number}, {"Idling", type text}, {"% Idling", type number}, {"Stopped", type text}, {"% Stopped", type number}, {"Stops", Int64.Type}, {"Miles", type number}}),
#"Inserted Time Subtraction" = Table.AddColumn(#"Changed Type", "Subtraction", each [End] - [Start], type duration),
#"Reordered Columns" = Table.ReorderColumns(#"Inserted Time Subtraction",{"Vehicle", "Group", "Start", "End", "Moving", "% Moving", "Idling", "% Idling", "Stopped", "% Stopped", "Stops", "Miles", "Subtraction", "Total Time"}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Reordered Columns", "Total Time", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"Total Time.hours", "Total Time.minutes", "Total Time.seconds"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Total Time.hours", Int64.Type}, {"Total Time.minutes", Int64.Type}, {"Total Time.seconds", Int64.Type}}),
#"Inserted Total Minutes" = Table.AddColumn(#"Changed Type1", "Subtraction Total Minutes", each Duration.TotalMinutes([Subtraction]), type number),
#"Added Custom" = Table.AddColumn(#"Inserted Total Minutes", "Total Time.Total minutes", each [Total Time.hours]*60 + [Total Time.minutes]+[Total Time.seconds]/60)
in
#"Added Custom"


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

5 REPLIES 5
fstupot
Helper II
Helper II

hi all,

 

the start/end time is not the data from where the moving time is calculated so it doesnt work

 

i dont understand why powerbi can just display it as it shows in excel.

 

really annoying x

Nathaniel_C
Super User
Super User

Hi @fstupot ,

I brought the two times into PQ and then let PQ create the duration. 

 


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

duration23.PNG

 

duration.PNG





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

Proud to be a Super User!




fstupot
Helper II
Helper II

VehicleGroupStartEndTotal TimeMoving% MovingIdling% IdlingStopped% StoppedStopsMiles
BF63XUVStaff_Lichfield OPS02/11/2020 08:0525/11/2020 14:3177:46:0924:29:5331.522:03:1628.3624:30:5531.5259457.6
BF67EUKStaff_Leek OPS03/11/2020 07:2725/11/2020 15:39111:49:5232:36:4929.1611:49:5610.5850:06:3144.81107618.9
BF67EUUStaff_Lichfield OPS02/11/2020 11:3925/11/2020 13:5286:52:0724:43:0128.4529:13:4733.6517:42:5220.3969460.4
BF67EUVStaff_Gailey OPS02/11/2020 07:2325/11/2020 15:00125:52:2039:36:5131.4708:05:156.4361:00:3048.47145804.7
BF67EUWStaff_Lichfield OPS02/11/2020 06:4425/11/2020 14:0383:54:5427:08:1132.3406:19:197.5327:27:4932.7374459.2
BF67EUYStaff_Surface Treatments02/11/2020 07:1225/11/2020 14:03123:06:2823:28:0019.0610:27:268.4984:39:2868.77133480.3

Thanks for the data @fstupot 

 

i'm not entirely sure where your total time is calculated, so if @Nathaniel_C  's solution helps, great. if not, you can try split column by delimiter to convert your duration columns into numeric columns

 

paste the below code into advanced editor to see what i mean

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZLLbhNRDIZfJZp15fpyrl4iAQuQQArhoiqqojIREYVFCQveHtsnNCPSRaWRxmP7+Hzz+7+5mV68KvJ583G6mtbH3X5/+/Zw921/mO+/rt69X1sW+ZrompFxhU0xW4rzY4qSClmqVk1FsXs1KXfNYqEQRD8rilLxsIGU0SSoOZ+a2N7ZD6dcoUzbq+CqLzdvzlzz/P0fkpyRqnL9Dymr+Cgi0mQgPltYpdiXd3YIklM1QoTcnAAVy/iflKBRlHx6oQZ9QbV5jlp2QXAs0WTgtGJvjdEmRBJFGtqkkKurNSavikDxFJm8PM4yQowtIVdBSAuw8xpf7w73858ndmiCyYVgiH4JZ8dij6W7YJnGfoIltq/kOAWShCx20PboIG00UfxBwwR1gfXpWe6yBaULd6Ff1Ey3ZI9XqxoIBRiDeMoOkknmelQI37G7Yqzbmqqnagp3deAF15dHrvXvh/3ubl59eJh3xx/zz+OvC9mIn4YjFrcNu4Ms5HZSswMOczkLe2gaOVIz7/fRXxrUkE0kRLTdTtvtXw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Vehicle = _t, Group = _t, Start = _t, End = _t, #"Total Time" = _t, Moving = _t, #"% Moving" = _t, Idling = _t, #"% Idling" = _t, Stopped = _t, #"% Stopped" = _t, Stops = _t, Miles = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Vehicle", type text}, {"Group", type text}, {"Start", type datetime}, {"End", type datetime}, {"Total Time", type text}, {"Moving", type text}, {"% Moving", type number}, {"Idling", type text}, {"% Idling", type number}, {"Stopped", type text}, {"% Stopped", type number}, {"Stops", Int64.Type}, {"Miles", type number}}),
#"Inserted Time Subtraction" = Table.AddColumn(#"Changed Type", "Subtraction", each [End] - [Start], type duration),
#"Reordered Columns" = Table.ReorderColumns(#"Inserted Time Subtraction",{"Vehicle", "Group", "Start", "End", "Moving", "% Moving", "Idling", "% Idling", "Stopped", "% Stopped", "Stops", "Miles", "Subtraction", "Total Time"}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Reordered Columns", "Total Time", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"Total Time.hours", "Total Time.minutes", "Total Time.seconds"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Total Time.hours", Int64.Type}, {"Total Time.minutes", Int64.Type}, {"Total Time.seconds", Int64.Type}}),
#"Inserted Total Minutes" = Table.AddColumn(#"Changed Type1", "Subtraction Total Minutes", each Duration.TotalMinutes([Subtraction]), type number),
#"Added Custom" = Table.AddColumn(#"Inserted Total Minutes", "Total Time.Total minutes", each [Total Time.hours]*60 + [Total Time.minutes]+[Total Time.seconds]/60)
in
#"Added Custom"


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

AllisonKennedy
Super User
Super User

Clear the formatting in Excel - what is the value actually entered in as? Is it date or text? 

 

If you can provide some sample data in the actual format we can help better.

 

The Power BI duration data type is converted to decimal number in the report.

https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-data-types#datetime-types


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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