Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

spread calls duration that exceed 30 mins over multiple 30 mins intervals over the day.

Hi team, I would like your help on this: I am working on a table that has multiple columns:  User, StartTime , EndTime , AuxCode and Duration columns. I would like to compute the number of AuxCode...
  • Jimmy801's avatar
    Jimmy801
    6 years ago

    Hello Anonymous 

     

    I've created something really nice

    But I think the logic has to be changed, meaning, creating a talble, considering the lowest start time and the highest end time and then connect to the call-table to do the calculation

    let
    
        
        
        Quelle = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTWMzTSMzIwtFQwsLAyMFDSQRMyNgUKJSfm5CjF6qArNzFFU26JrDwWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Start = _t, End = _t, Type = _t]),
        ChangeType = Table.TransformColumnTypes
            (
                Quelle,
                {
                    {"Start", type datetime}, 
                    {"End", type datetime}, 
                    {"Type", type text}
                }
            ),
            GetListTimesStart = List.DateTimes
        (
            List.Min
            (
                ChangeType[Start]
            )
            -
            #duration(0,0,Time.Minute
            (
                List.Min
                (
                    ChangeType[Start]
                )
            ),0),
            Duration.Minutes
            (
                List.Max
                (
                    ChangeType[End]
                )
                -
                List.Min
                (
                    ChangeType[Start]
                )
    
            )
            / 30+2,
            #duration(0,0,30,0)
        ),
        GetListTimeEnd = List.Transform(GetListTimesStart, each _ + #duration(0,0,30,0)),
        CreateTabel = Table.FromColumns({GetListTimesStart,GetListTimeEnd}, {"Start", "End"}),
        AddCallTable = Table.AddColumn
        (
            CreateTabel, 
            "Merge Tables", 
            (Time)=> Table.SelectRows
            (
                ChangeType, 
                (select)=> select[Start]<=Time[End] and Time[Start] <= select[End] 
            )
        ),
        ExpandCallTimes = Table.ExpandTableColumn
        (
            AddCallTable, 
            "Merge Tables", 
            {"Start", "End", "Type"}, 
            {"Call.Start", "Call.End", "Type"}
        ),
        ChangeToDateTime = Table.TransformColumnTypes
        (
            ExpandCallTimes,
            {
                {"Start", type datetime}, 
                {"End", type datetime}, 
                {"Call.Start", type datetime}, 
                {"Call.End", type datetime}}
        ),
        CalculateDuration = Table.AddColumn
        (
            ChangeToDateTime, 
            "Duration", 
            each Duration.TotalSeconds
            (
                (if [End]<[Call.End] then [End] else [Call.End])-
                (if [Call.Start]>[Start] then [Call.Start] else [Start])
            )
        ),
        DeleteCallColumns = Table.RemoveColumns
        (
            CalculateDuration,
            {"Call.Start", "Call.End"}
        )
    in
        DeleteCallColumns

     

    What do you think about it?

    If this post helps or solves your problem, please mark it as solution.
    Kudos are nice to - thanks
    Have fun

    Jimmy