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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Bu__
Frequent Visitor

Find duration spent between 2 dates in multiple rows

Have a data like below

Ticket numCreated
Ticket_111/3/2022 0:06
Ticket_111/3/2022 0:18
Ticket_111/3/2022 0:21
Ticket_111/3/2022 0:22
Ticket_111/3/2022 0:23
Ticket_111/3/2022 0:24
Ticket_111/3/2022 0:26
Ticket_212/12/2022 13:40
Ticket_212/12/2022 13:41
Ticket_212/12/2022 13:43
Ticket_212/12/2022 13:45
Ticket_212/12/2022 13:45
Ticket_212/12/2022 13:46

Would like to calculate Time Taken in each ticket by subtracting the created column data for each row for all ticket num.

Here Time taken for 1st row calculated as ( 11/3/2022 0:18 - 11/3/2022 0:06) *24 = 0.1919444 ....until another ticket starts, to have 0 before a new ticket starts

Results to look something like below table

Ticket numCreated Time Taken
Ticket_111/3/2022 0:060.1919444
Ticket_111/3/2022 0:180.0547222
Ticket_111/3/2022 0:210.0175
Ticket_111/3/2022 0:220.0108333
Ticket_111/3/2022 0:230.0166667
Ticket_111/3/2022 0:240.0369444
Ticket_111/3/2022 0:260
Ticket_212/12/2022 13:400.0158333
Ticket_212/12/2022 13:410.0205556
Ticket_212/12/2022 13:430.0419444
Ticket_212/12/2022 13:450.0041667
Ticket_212/12/2022 13:450.0061111
Ticket_212/12/2022 13:46

0

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understodd your question correctly, but I tried to create a sample pbix file like below.

It is for creating a new column, and the result is described in Second.

Please check the below picture and the attached pbix file.

 

OFFSET function (DAX) - DAX | Microsoft Learn

 

COALESCE function (DAX) - DAX | Microsoft Learn

 

 

Jihwan_Kim_0-1700901733104.png

 

expected reuslt CC = 
VAR _currentdatetime = Data[Created]
VAR _nextdatetime =
    MAXX (
        OFFSET (
            1,
            SUMMARIZE ( Data, Data[Ticket num], Data[Created] ),
            ORDERBY ( Data[Created], ASC ),
            ,
            PARTITIONBY ( Data[Ticket num] )
        ),
        Data[Created]
    )
RETURN
    COALESCE ( DATEDIFF ( _currentdatetime, _nextdatetime, SECOND ), 0 )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understodd your question correctly, but I tried to create a sample pbix file like below.

It is for creating a new column, and the result is described in Second.

Please check the below picture and the attached pbix file.

 

OFFSET function (DAX) - DAX | Microsoft Learn

 

COALESCE function (DAX) - DAX | Microsoft Learn

 

 

Jihwan_Kim_0-1700901733104.png

 

expected reuslt CC = 
VAR _currentdatetime = Data[Created]
VAR _nextdatetime =
    MAXX (
        OFFSET (
            1,
            SUMMARIZE ( Data, Data[Ticket num], Data[Created] ),
            ORDERBY ( Data[Created], ASC ),
            ,
            PARTITIONBY ( Data[Ticket num] )
        ),
        Data[Created]
    )
RETURN
    COALESCE ( DATEDIFF ( _currentdatetime, _nextdatetime, SECOND ), 0 )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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