Forum Discussion

vazfelipe's avatar
vazfelipe
Frequent Visitor
8 years ago
Solved

Calculating time difference in a vertical column

Hi guys, I have two columns, one with repetead dates and other one with the hour the transaction occured. Do there's a way to calculate the time duration in certain day? For example, here below I ...
  • v-ljerr-msft's avatar
    v-ljerr-msft
    8 years ago

    Hi vazfelipe,

     

    To group the Date Column and SUM the hours in that range of date, you can firstly group by the "Order Day" column and get the Min and Max "Order Hour" in the range of the date.

     

     

    Then you should be able to use the formula(M) below to add a custom column to SUM the hours in that range of date.

    =Duration.Hours([MaxHour]-[MinHour])

     

    Following is the M query of all steps for your reference:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDRX0lEytjIwtDIwUHD0VYrVQZExsjIxAckEYMgY45QxQZUx0jeGyRgaWJkY4ZAyRJKKBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Order Day" = _t, #"Order Hour" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Order Day", type date}, {"Order Hour", type time}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Order Day"}, {{"MinHour", each List.Min([Order Hour]), type time}, {"MaxHour", each List.Max([Order Hour]), type time}}),
        #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Hours", each Duration.Hours([MaxHour]-[MinHour]))
    in
        #"Added Custom"

     

    Regards