Forum Discussion

Arroios2020's avatar
Arroios2020
Regular Visitor
6 years ago
Solved

Calculate Response Time each time

Hi
I am having trouble to calculate the response time of each message.

I have ID_Conversation for each conversation and a conversation can have multiple messagas (Content column). The column is_by_source tell me if the message was published by me or the client. What I want to know is how many hours and minutes I took to answer each message of client (is_by_source=False) and also how many time it took the customer to answer. Here it is the table:

 ABCDEF
1Id_ConversationsCreated_DateTimeContent_TypeIs_By_SourceContentDesired
25ee9cee62e583f6432901f7317/06/2020 08:05messageFALSEtext 
35ee9cee62e583f6432901f7317/06/2020 09:08messageTRUEtext101:02:04 (B3-B2)
45eeacde9458a68a0d944eaf918/06/2020 02:13postFALSEtext2 
55eeacde9458a68a0d944eaf918/06/2020 08:34commentTRUEtext306:20:23 (B5-B4
65eeacde9458a68a0d944eaf918/06/2020 09:22messageFALSEtext400:47:41 (B6-B5)
75eeacde9458a68a0d944eaf918/06/2020 09:47messageTRUEtext500:25:42 (B7-B6)

Can you help me?

Thanks!



  • Hi Arroios2020 

    Column =
    RANKX (
        FILTER (
            'Table',
            'Table'[Id_Conversations] = EARLIER ( 'Table'[Id_Conversations] )
        ),
        [Created_DateTime],
        ,
        ASC,
        DENSE
    )
    
    
    Column 2 =
    CALCULATE (
        MAX ( 'Table'[Created_DateTime] ),
        FILTER (
            'Table',
            'Table'[Id_Conversations] = EARLIER ( 'Table'[Id_Conversations] )
                && 'Table'[Column]
                    = EARLIER ( 'Table'[Column] ) - 1
        )
    )
    
    
    Column 3 =
    VAR ts =
        IF (
            [Column 2] <> BLANK (),
            DATEDIFF ( [Column 2], [Created_DateTime], SECOND )
        )
    VAR h =
        INT ( ts / 3600 )
    VAR d =
        INT ( h / 24 )
    VAR m =
        INT ( MOD ( ts, 3600 ) / 60 )
    VAR s = ts - h * 3600 - m * 60
    VAR hh =
        IF ( LEN ( h ) = 1, 0 & h, h )
    VAR mm =
        IF ( LEN ( m ) = 1, 0 & m, m )
    VAR ss =
        IF ( LEN ( s ) = 1, 0 & s, s )
    RETURN
        IF (
            [Column 2] <> BLANK (),
            IF (
                d = BLANK (),
                hh & ":" & mm & ":" & ss,
                d & " " & hh & ":" & mm & ":" & ss
            )
        )
    

    Best Regards
    Maggie
    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

5 Replies

    • Arroios2020's avatar
      Arroios2020
      Regular Visitor

      Hi Greg_Deckler 

       

      Great article! I tried to use your formula but still I am having osme problems:


      Last_Reply =

      VAR next = MINX(FILTER(Table1,

      Table1[Id_Conversations]=EARLIER(Table1[Id_Conversations]) &&

      Table1[Created_DateTime]>EARLIER(Table1[Created_DateTime]) &&

      Table1[Is_By_Source]<>"True"

      ),Table1[Created_DateTime])

      RETURN IF(Table1[Is_By_Source]="False", 0,IF(ISBLANK(next),

      DATEDIFF(Table1[Created_Date],NOW(),HOUR),

      DATEDIFF(Table1[Created_Date],next,HOUR)

      )

      )

      The results does not look ideal:

       

      Id_ConversationsId_ContentCreated_DateTimeLast_ReplyContent_TypeIs_By_SourceContent
      5eeacde9458a68a0d944eaf95eeacde80314c8640ea3ae3e18/06/2020 02:130postFALSExxx
      5eeacde9458a68a0d944eaf95eeb270e1326c983451a0b2918/06/2020 08:3418commentTRUExxxxx
      5eeacde9458a68a0d944eaf95eeb32398c610c9a94ed752a18/06/2020 09:220messageFALSExxxxxxx
      5eeacde9458a68a0d944eaf95eeb383e07f3f3d26e26871218/06/2020 09:471024messageTRUExxxx
      • v-juanli-msft's avatar
        v-juanli-msft
        Icon for Community Support rankCommunity Support

        Hi Arroios2020 

        Column =
        RANKX (
            FILTER (
                'Table',
                'Table'[Id_Conversations] = EARLIER ( 'Table'[Id_Conversations] )
            ),
            [Created_DateTime],
            ,
            ASC,
            DENSE
        )
        
        
        Column 2 =
        CALCULATE (
            MAX ( 'Table'[Created_DateTime] ),
            FILTER (
                'Table',
                'Table'[Id_Conversations] = EARLIER ( 'Table'[Id_Conversations] )
                    && 'Table'[Column]
                        = EARLIER ( 'Table'[Column] ) - 1
            )
        )
        
        
        Column 3 =
        VAR ts =
            IF (
                [Column 2] <> BLANK (),
                DATEDIFF ( [Column 2], [Created_DateTime], SECOND )
            )
        VAR h =
            INT ( ts / 3600 )
        VAR d =
            INT ( h / 24 )
        VAR m =
            INT ( MOD ( ts, 3600 ) / 60 )
        VAR s = ts - h * 3600 - m * 60
        VAR hh =
            IF ( LEN ( h ) = 1, 0 & h, h )
        VAR mm =
            IF ( LEN ( m ) = 1, 0 & m, m )
        VAR ss =
            IF ( LEN ( s ) = 1, 0 & s, s )
        RETURN
            IF (
                [Column 2] <> BLANK (),
                IF (
                    d = BLANK (),
                    hh & ":" & mm & ":" & ss,
                    d & " " & hh & ":" & mm & ":" & ss
                )
            )
        

        Best Regards
        Maggie
        Community Support Team _ Maggie Li
        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • v-juanli-msft's avatar
    v-juanli-msft
    Icon for Community Support rankCommunity Support

    Hi Arroios2020 

    Great blog from Greg_Deckler, hope that provides ideas to slove your problem.

    If not, please feel free to ask here.

     

    Best Regards

    Maggie