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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors