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
sciomac
Frequent Visitor

Compute duration when start time and end time are in the same column

Hi everyone,

 

I hope someone can help me. I am trying to see the duration of some jobs (orders) but the table where everything is registered has Start_time and End_time in the same column. There are not two columns one for Start_time and a second one for End_time. You can see the data the way I have it.

 

Screenshot 2019-11-27 at 18.25.14.png

 

And I would like to have the data in the Query Editor like this:

 

Screenshot 2019-11-27 at 18.33.39.png

 

I am clueless, I have tried different approaches but nothing worked. I can provide sample data if anyone needs it.

 

Thank you,

 

Sciomac

1 ACCEPTED SOLUTION

Hi @sciomac 

How does this look?
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
startend.PNG

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fdS9boMwEADgV4mYI+XO9vnAczp06tBKHVBURQpDVTWtEEvfvkeIobh3LDEEfblf0rbV47HaV69f/UfXv92uj+ehk+Pl/fN2/HyPx1N/6fqdPD/t24pjA/IdonwAHtAdHCDLDSffJEdy9Tyc+2E3TL+BUZ7eIapQVEw+yNXD9aIoJ/exRAgJQyJQwsUMvQUp+ViGm1WwVBS4VR2pMIzVkTOri5bi5Nz/cA4yZLWZY21+Kq+QMFdYb8jQFJkurNlgpAW818igL8woQ4JyEgtDtTWieJrEX5X7wuDmYGG9ZJAC2/Nj8BbEdKtAmx9DMBTx1MuyKZQh2ZCUPZNAdxhVKBs6LhqW3ZwZm0w2rXz7ljTrPISwHkKARLW9nwyNBVFGYU0PIStaNUX+WihsREPUnWSJ5bu3IGcip5WG2S2bsoZk9KTOMFhQVozLNGdFWproE+KU50pJkqdf", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"ID", Int64.Type}, {"Worker_ID", Int64.Type}, {"Date", type date}, {"Time", type time}, {"Type", type text}, {"Order ID", Int64.Type}}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Changed Type1",{{"Worker_ID", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type2", each ([Type] = "Start time")),
    #"Renamed Columns" = Table.RenameColumns(#"Filtered Rows",{{"Time", "Start time"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"Type"}),
    #"Appended Query" = Table.Combine({#"Removed Columns", Endtime}),
    #"Sorted Rows" = Table.Sort(#"Appended Query",{{"ID", Order.Ascending}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Sorted Rows",{"ID", "Worker_ID", "Date", "Start time", "Endtime", "Order ID"}),
    #"Filled Up" = Table.FillUp(#"Reordered Columns",{"Endtime"}),
    #"Sorted Rows1" = Table.Sort(#"Filled Up",{{"Order ID", Order.Ascending}}),
    #"Filtered Rows1" = Table.SelectRows(#"Sorted Rows1", each ([Start time] <> null)),
    #"Sorted Rows2" = Table.Sort(#"Filtered Rows1",{{"ID", Order.Ascending}}),
    #"Removed Columns1" = Table.RemoveColumns(#"Sorted Rows2",{"ID"})
in
    #"Removed Columns1"


Will post pbix soon.





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

Proud to be a Super User!




View solution in original post

4 REPLIES 4
Nathaniel_C
Super User
Super User

Hi @sciomac ,
If you would copy and paste your data directly into your post, instead of pictures, we can do the same into Power Query and perhaps solve your issue.
Thank you,


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





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

Proud to be a Super User!




rThank you for the tip @Nathaniel_C . Here the data

 

IDWorker_IDDateTimeTypeOrder ID
76901101/12/20177:39:25Start time1617
76911101/12/20179:26:34Endtime1617
7692601/12/201710:14:50Start time1616
7693601/12/201710:15:36Endtime1616
7694601/12/201710:16:15Start time1617
7695601/12/201714:26:52Endtime1617
7696601/12/201714:27:22Start time1620
76971101/12/201715:33:36Start time1606
76981101/12/201715:33:49Endtime1606
76991101/12/201715:33:56Start time1607
77001101/12/201715:34:06Endtime1607
7701601/12/201715:37:15Endtime1620
77021104/12/20179:20:47Start time1617
77031104/12/20179:21:00Endtime1617
77041104/12/20179:57:49Start time1605
77051104/12/20179:57:55Start time1604
77061104/12/201710:26:51Endtime1604
77071104/12/201710:27:24Endtime1605
7708604/12/201715:40:58Start time1620
7709604/12/201715:41:20Endtime1620
7710605/12/20179:39:54Start time1620
7711605/12/20179:40:12Endtime1620
7712605/12/20179:40:28Start time1621
77131105/12/20179:50:58Start time1628
77141105/12/20179:51:07Endtime1628
7715605/12/201713:11:28Endtime1621

Hi @sciomac ,
Thank you, loading and working on it.
Nathaniel





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

Proud to be a Super User!




Hi @sciomac 

How does this look?
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
startend.PNG

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fdS9boMwEADgV4mYI+XO9vnAczp06tBKHVBURQpDVTWtEEvfvkeIobh3LDEEfblf0rbV47HaV69f/UfXv92uj+ehk+Pl/fN2/HyPx1N/6fqdPD/t24pjA/IdonwAHtAdHCDLDSffJEdy9Tyc+2E3TL+BUZ7eIapQVEw+yNXD9aIoJ/exRAgJQyJQwsUMvQUp+ViGm1WwVBS4VR2pMIzVkTOri5bi5Nz/cA4yZLWZY21+Kq+QMFdYb8jQFJkurNlgpAW818igL8woQ4JyEgtDtTWieJrEX5X7wuDmYGG9ZJAC2/Nj8BbEdKtAmx9DMBTx1MuyKZQh2ZCUPZNAdxhVKBs6LhqW3ZwZm0w2rXz7ljTrPISwHkKARLW9nwyNBVFGYU0PIStaNUX+WihsREPUnWSJ5bu3IGcip5WG2S2bsoZk9KTOMFhQVozLNGdFWproE+KU50pJkqdf", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"ID", Int64.Type}, {"Worker_ID", Int64.Type}, {"Date", type date}, {"Time", type time}, {"Type", type text}, {"Order ID", Int64.Type}}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Changed Type1",{{"Worker_ID", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type2", each ([Type] = "Start time")),
    #"Renamed Columns" = Table.RenameColumns(#"Filtered Rows",{{"Time", "Start time"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"Type"}),
    #"Appended Query" = Table.Combine({#"Removed Columns", Endtime}),
    #"Sorted Rows" = Table.Sort(#"Appended Query",{{"ID", Order.Ascending}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Sorted Rows",{"ID", "Worker_ID", "Date", "Start time", "Endtime", "Order ID"}),
    #"Filled Up" = Table.FillUp(#"Reordered Columns",{"Endtime"}),
    #"Sorted Rows1" = Table.Sort(#"Filled Up",{{"Order ID", Order.Ascending}}),
    #"Filtered Rows1" = Table.SelectRows(#"Sorted Rows1", each ([Start time] <> null)),
    #"Sorted Rows2" = Table.Sort(#"Filtered Rows1",{{"ID", Order.Ascending}}),
    #"Removed Columns1" = Table.RemoveColumns(#"Sorted Rows2",{"ID"})
in
    #"Removed Columns1"


Will post pbix soon.





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

Proud to be a Super User!




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.

Top Solution Authors