Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
rg72
Frequent Visitor

Average duration in dd:hh:mm:ss

First post - please be kind 🙂

 

Using PowerBi to pull common Incident and Task Ticket information from Service Now and combine via a Union query.

 

I'm looking to show the Average Incident Resolve Time and the Average Task resolve time.

 

I'm using DATEDIFF as follows ...

 

DifferenceSECs = DATEDIFF(ServiceNow[opened_at],ServiceNow[resolved_at],SECOND)

 

opened_at = 17/07/2017 15:57:40

resolved_at = 18/07/2017 10:24:00

DifferenceSECs = 66380

 

I'm then taking that result in seconds and converting it to a duration

 

New Duration = format(((ServiceNow[DifferenceSECs] / 60)/60)/24, "dd:HH:mm:ss")

 

New Duration = 30:18:26:20

 

My problem is why has the result got 30 days added at the start.

 

I'm also getting examples where days are being removed.

 

opened_at = 18/07/2017 10:39:14

resolved_at = 20/07/2017 13:09:44

DifferenceSECs = 181830

New Duration = 01:02:30:30 - Should be 02:02:30:30

 

Once I have the correct New Duration, I'm then looking to get the average for which I'm using ..

 

FORMAT(AVERAGEA(ServiceNow[DifferenceSECs]),"DD:HH:MM: SS")

 

Apologies for the long post, but is anyone able to advise where I'm going wrong.

 

Thanks in advance

 

Rob

 

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @rg72,

 

Please try below formulas:

DifferenceSECs =
DATEDIFF ( ServiceNow[opened_at], ServiceNow[resolved_at], SECOND )

Duration =
RIGHT ( "0" & INT ( ServiceNow[DifferenceSECs] / ( 24 * 60 * 60 ) ), 2 )
    & ":"
    & RIGHT (
        "0"
            & INT (
                (
                    ServiceNow[DifferenceSECs]
                        - INT ( ServiceNow[DifferenceSECs] / ( 24 * 60 * 60 ) )
                            * ( 24 * 60
                            * 60 )
                )
                    / 3600
            ),
        2
    )
    & ":"
    & RIGHT (
        "0"
            & INT (
                (
                    ServiceNow[DifferenceSECs]
                        - INT ( ServiceNow[DifferenceSECs] / 3600 )
                            * 3600
                )
                    / 60
            ),
        2
    )
    & ":"
    & RIGHT (
        "0"
            & (
                ServiceNow[DifferenceSECs]
                    - INT ( ServiceNow[DifferenceSECs] / 60 )
                        * 60
            ),
        2
    )

Duration Average =
RIGHT (
    "0"
        & INT ( AVERAGEA ( ServiceNow[DifferenceSECs] ) / ( 24 * 60 * 60 ) ),
    2
)
    & ":"
    & RIGHT (
        "0"
            & INT (
                (
                    AVERAGEA ( ServiceNow[DifferenceSECs] )
                        - INT ( AVERAGEA ( ServiceNow[DifferenceSECs] ) / ( 24 * 60 * 60 ) )
                            * ( 24 * 60
                            * 60 )
                )
                    / 3600
            ),
        2
    )
    & ":"
    & RIGHT (
        "0"
            & INT (
                (
                    AVERAGEA ( ServiceNow[DifferenceSECs] )
                        - INT ( AVERAGEA ( ServiceNow[DifferenceSECs] ) / 3600 )
                            * 3600
                )
                    / 60
            ),
        2
    )
    & ":"
    & RIGHT (
        "0"
            & (
                AVERAGEA ( ServiceNow[DifferenceSECs] )
                    - INT ( AVERAGEA ( ServiceNow[DifferenceSECs] ) / 60 )
                        * 60
            ),
        2
    )

1.PNG

 

Best regards,

Yuliana Gu

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

View solution in original post

2 REPLIES 2
v-yulgu-msft
Employee
Employee

Hi @rg72,

 

Please try below formulas:

DifferenceSECs =
DATEDIFF ( ServiceNow[opened_at], ServiceNow[resolved_at], SECOND )

Duration =
RIGHT ( "0" & INT ( ServiceNow[DifferenceSECs] / ( 24 * 60 * 60 ) ), 2 )
    & ":"
    & RIGHT (
        "0"
            & INT (
                (
                    ServiceNow[DifferenceSECs]
                        - INT ( ServiceNow[DifferenceSECs] / ( 24 * 60 * 60 ) )
                            * ( 24 * 60
                            * 60 )
                )
                    / 3600
            ),
        2
    )
    & ":"
    & RIGHT (
        "0"
            & INT (
                (
                    ServiceNow[DifferenceSECs]
                        - INT ( ServiceNow[DifferenceSECs] / 3600 )
                            * 3600
                )
                    / 60
            ),
        2
    )
    & ":"
    & RIGHT (
        "0"
            & (
                ServiceNow[DifferenceSECs]
                    - INT ( ServiceNow[DifferenceSECs] / 60 )
                        * 60
            ),
        2
    )

Duration Average =
RIGHT (
    "0"
        & INT ( AVERAGEA ( ServiceNow[DifferenceSECs] ) / ( 24 * 60 * 60 ) ),
    2
)
    & ":"
    & RIGHT (
        "0"
            & INT (
                (
                    AVERAGEA ( ServiceNow[DifferenceSECs] )
                        - INT ( AVERAGEA ( ServiceNow[DifferenceSECs] ) / ( 24 * 60 * 60 ) )
                            * ( 24 * 60
                            * 60 )
                )
                    / 3600
            ),
        2
    )
    & ":"
    & RIGHT (
        "0"
            & INT (
                (
                    AVERAGEA ( ServiceNow[DifferenceSECs] )
                        - INT ( AVERAGEA ( ServiceNow[DifferenceSECs] ) / 3600 )
                            * 3600
                )
                    / 60
            ),
        2
    )
    & ":"
    & RIGHT (
        "0"
            & (
                AVERAGEA ( ServiceNow[DifferenceSECs] )
                    - INT ( AVERAGEA ( ServiceNow[DifferenceSECs] ) / 60 )
                        * 60
            ),
        2
    )

1.PNG

 

Best regards,

Yuliana Gu

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

Many thanks - Works a treat 🙂

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.