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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Tucker1991
Frequent Visitor

Difference Between Consecutive Rows - When Date is The Same

Hi,

 

So theoretically I know exactly what I want to do. I am simply having a difficult time executing that in Power Bi.

 

Basically I have a ton of data on helpdesk tickets. 

 

What I want is the difference in closure times for conescutive tickets per agent per day. 

 

I.E. How long did Agent A spend between closing ticket 1 versus ticket 2 versus ticket 3 versus ticket 4 on Septemeber 12th ect... ect...

 

 

Sample Ticket Data.PNG

 

The actual data has about 20 agents and over 75,000 tickets.

1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Tucker1991,

 

Please create some calculated columns with below formulas:

Index =
CALCULATE (
    COUNTROWS ( 'Agent ticket' ),
    FILTER (
        ALL ( 'Agent ticket' ),
        'Agent ticket'[Agent] = EARLIER ( 'Agent ticket'[Agent] )
            && 'Agent ticket'[Date Closed].[Date]
                = EARLIER ( 'Agent ticket'[Date Closed].[Date] )
            && 'Agent ticket'[Ticket ID] < EARLIER ( 'Agent ticket'[Ticket ID] )
    )
)
    + 1

Closed time for previous Ticket =
CALCULATE (
    MAX ( 'Agent ticket'[Date Closed] ),
    FILTER (
        ALLEXCEPT (
            'Agent ticket',
            'Agent ticket'[Agent],
            'Agent ticket'[Date Closed].[Date]
        ),
        'Agent ticket'[Index]
            = EARLIER ( 'Agent ticket'[Index] ) - 1
    )
)

spend time =
DATEDIFF (
    'Agent ticket'[Closed time for previous Ticket],
    'Agent ticket'[Date Closed],
    SECOND
)

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
Microsoft Employee
Microsoft Employee

Hi @Tucker1991,

 

Please create some calculated columns with below formulas:

Index =
CALCULATE (
    COUNTROWS ( 'Agent ticket' ),
    FILTER (
        ALL ( 'Agent ticket' ),
        'Agent ticket'[Agent] = EARLIER ( 'Agent ticket'[Agent] )
            && 'Agent ticket'[Date Closed].[Date]
                = EARLIER ( 'Agent ticket'[Date Closed].[Date] )
            && 'Agent ticket'[Ticket ID] < EARLIER ( 'Agent ticket'[Ticket ID] )
    )
)
    + 1

Closed time for previous Ticket =
CALCULATE (
    MAX ( 'Agent ticket'[Date Closed] ),
    FILTER (
        ALLEXCEPT (
            'Agent ticket',
            'Agent ticket'[Agent],
            'Agent ticket'[Date Closed].[Date]
        ),
        'Agent ticket'[Index]
            = EARLIER ( 'Agent ticket'[Index] ) - 1
    )
)

spend time =
DATEDIFF (
    'Agent ticket'[Closed time for previous Ticket],
    'Agent ticket'[Date Closed],
    SECOND
)

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.
Tucker1991
Frequent Visitor

Would I basically want to use a DAX formula similar to the one below.

 

Column = DATEDIFF (
'Ticket Data'[Time],
CALCULATE (
MIN ( [Time] ),
FILTER ( ALL ( 'Ticket Data' ), [INDEX] < EARLIER ( 'Ticket Data'[INDEX] ) )
),
SECOND
)

 

But  add IF Agent and Date is the same?

 

Thanks,

 

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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