Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Calculate average TAT for each category

Hi,

 

I have to calulate Average Turn Around time between DEACTIVATED & ACTIVATED status for each unique "Alert type".

 

Eg: Rows 1 to 26 is one Alert type, but i have many tickets Activated & deactivated for the same, All i need is to see how is the Average TAT time maintained in each alert type.

 

Also, If alert type doesnot have deactived status, the TAT should not be calculated...

 

 

I am not sure how to handle this case, Can anyone help with this

 

  • Hi Anonymous ,

     

    What is the calculation you need to do exactly? do you need to calculate the time difference between each status and then the average?

     

    Please see this post regarding How to Get Your Question Answered Quickly (courtesy of @Greg_Deckler) and How to provide sample data in the Power BI Forum (courtesy of @ImkeF).

     

    Can you please share a mockup data or sample of your PBIX file. You can use a onedrive, google drive, we transfer or similar link to upload your files.

    If the information is sensitive please share it trough private message.

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Anonymous ,

     

    According to my understanding, you want to calculate the average time calculated by deactived time - activated time of each AlertType ,right?

     

    You could follow these steps:

    1. Add a rank column to table:

    Rank =
    VAR a = [Alert Type]
    VAR t1 =
        FILTER ( ALL ( 'Table' ), 'Table'[Alert Type] = a )
    RETURN
        RANKX ( t1, RANKX ( t1, [Time],, ASC, SKIP ),, ASC, SKIP )

    2. Use the following formula to create a calculated table:

    New Table =
    VAR _t1 =
        ADDCOLUMNS (
            SELECTCOLUMNS (
                CALCULATETABLE ( 'Table', 'Table'[Status] = "Activated" ),
                "AlertType", [Alert Type],
                "Ac", [Time],
                "Index", [Rank]
            ),
            "De",
                LOOKUPVALUE (
                    'Table'[Time],
                    'Table'[Alert Type], [AlertType],
                    'Table'[Rank], [Index] + 1
                )
        )
    RETURN
        ADDCOLUMNS ( _t1, "TimeDiff", DATEDIFF ( [Ac], [De], SECOND ) )

    3. Calculate the average time

    Average Measure =
    CALCULATE (
        AVERAGE ( 'New Table'[TimeDiff] ),
        FILTER ( 'New Table', 'New Table'[AlertType] = MAX ( 'New Table'[AlertType] ) )
    )

    Or 

    Average Column =
    CALCULATE (
        AVERAGE ( 'New Table'[TimeDiff] ),
        ALLEXCEPT ( 'New Table', 'New Table'[AlertType] )
    )

    The final output is shown below:

     

    Please take a look at the pbix file here.

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

5 Replies

  • Hi Anonymous ,

     

    What is the calculation you need to do exactly? do you need to calculate the time difference between each status and then the average?

     

    Please see this post regarding How to Get Your Question Answered Quickly (courtesy of @Greg_Deckler) and How to provide sample data in the Power BI Forum (courtesy of @ImkeF).

     

    Can you please share a mockup data or sample of your PBIX file. You can use a onedrive, google drive, we transfer or similar link to upload your files.

    If the information is sensitive please share it trough private message.

      • MFelix's avatar
        MFelix
        Icon for Super User rankSuper User

        Hi @sharm ,

         

        Looking at the data you have provided you need to do the following steps on the query editor:

         

        • Group Row By category (don't forget to select All Rows in the operation)

         

        • Add an Index Column
        • Expand all column from the column that present the values Table
        • Sort Columns by (order is very important):
          • Index
          • Time Received

         

        • Add an Index column
        • Format the columns
        • Add the following custom column:
        [Time Received] - (if [IndexAllRows] = 0 then null else if #"Changed Type" {[IndexAllRows] - 1} [Index] = #"Changed Type" {[IndexAllRows] } [Index] then #"Changed Type" {[IndexAllRows] - 1} [Time Received] else null )
        • Format the columns
        • If you want you can delete the index columns.

         

        Now just load the values on the PBI and you can then create the following measure using dax:

        Average time =
        FORMAT (
            TIME ( TRUNC ( AVERAGE ( 'Table'[Duration previous stage] ); 0 ); (
                AVERAGE ( 'Table'[Duration previous stage] )
                    - TRUNC ( AVERAGE ( 'Table'[Duration previous stage] ); 0 )
            ) * 60; 0 );
            "short time"
        )

         

         

        Check PBIX file attach.

         

        If this works please tell me so I can post the answer and you can accept it so it can help others.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    According to my understanding, you want to calculate the average time calculated by deactived time - activated time of each AlertType ,right?

     

    You could follow these steps:

    1. Add a rank column to table:

    Rank =
    VAR a = [Alert Type]
    VAR t1 =
        FILTER ( ALL ( 'Table' ), 'Table'[Alert Type] = a )
    RETURN
        RANKX ( t1, RANKX ( t1, [Time],, ASC, SKIP ),, ASC, SKIP )

    2. Use the following formula to create a calculated table:

    New Table =
    VAR _t1 =
        ADDCOLUMNS (
            SELECTCOLUMNS (
                CALCULATETABLE ( 'Table', 'Table'[Status] = "Activated" ),
                "AlertType", [Alert Type],
                "Ac", [Time],
                "Index", [Rank]
            ),
            "De",
                LOOKUPVALUE (
                    'Table'[Time],
                    'Table'[Alert Type], [AlertType],
                    'Table'[Rank], [Index] + 1
                )
        )
    RETURN
        ADDCOLUMNS ( _t1, "TimeDiff", DATEDIFF ( [Ac], [De], SECOND ) )

    3. Calculate the average time

    Average Measure =
    CALCULATE (
        AVERAGE ( 'New Table'[TimeDiff] ),
        FILTER ( 'New Table', 'New Table'[AlertType] = MAX ( 'New Table'[AlertType] ) )
    )

    Or 

    Average Column =
    CALCULATE (
        AVERAGE ( 'New Table'[TimeDiff] ),
        ALLEXCEPT ( 'New Table', 'New Table'[AlertType] )
    )

    The final output is shown below:

     

    Please take a look at the pbix file here.

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks Anonymous . It worked !