Forum Discussion

sciomac's avatar
sciomac
Frequent Visitor
6 years ago
Solved

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.

 

 

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

 

 

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

 

Thank you,

 

Sciomac

  • Nathaniel_C's avatar
    Nathaniel_C
    6 years ago

    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


    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.

4 Replies

  • Nathaniel_C's avatar
    Nathaniel_C
    Community Champion

    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

    • sciomac's avatar
      sciomac
      Frequent Visitor

      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