Forum Discussion

affanalvi's avatar
affanalvi
Regular Visitor
5 years ago
Solved

Sum Total Time Spent on Activity

Dear All,  I'm working on a report and I have different users performing same activity throughout the day. Each line item is considered as one transaction and I have date and time stamp for each tra...
  • ChrisMendoza's avatar
    5 years ago

    affanalvi -

    Here's a possibility:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("zdI7CoAwDAbgq0hnhSStj2arzp5AHLyC9x98gA+K1AxBXEKGb/gT/mEwrclNaLt1YtFPc0G4rcDOMVVZ6M2YK6BaDTUS5D9FFiQI1RAdqDsR3RAxANsyiewamsG/GwSBQYFxSeO2zGomfXtkQvb4xajcSVWLVCNSXqKuxikoVFT0U2V3NS4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [User = _t, Activity = _t, Date = _t, Time = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"User", type text}, {"Activity", type text}, {"Date", type date}, {"Time", type time}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Activity", "User", "Date"}, {{"Grouped", each _, type table [User=nullable text, Activity=nullable text, Date=nullable date, Time=nullable time]}, {"Min", each List.Min([Time]), type nullable time}, {"Max", each List.Max([Time]), type nullable time}}),
        #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Duration", each DateTime.From([Date]&[Max]) - DateTime.From([Date]&[Min])),
        #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Duration", type duration}}),
        #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Grouped", "Min", "Max"})
    in
        #"Removed Columns"

    Measure = FORMAT(SUM(TableName[Duration]),"hh:mm:ss")