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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
gunner
Frequent Visitor

Help with Time difference between multiple rows

Hi all, 

 

I am looking for some help calculating the time difference between 2 dates for values at different intervals throughout my data. Sample of the data is below.

 

Example: I need to find the time duration between User ABC = License Count 1 and User ABC = License Count -1, time duration between User XYZ = License Count 1 and User XYZ = License Count -1.

 

As you can see from the User ADE, there can be some number of rows between a license count = 1 and = -1 for the same user.

 

Any help gladly appreciated, thank you.

 

 

Timestamp (UTC)File AcquiredLicense CountUser
18/12/2017 0:01Acquired1ABC
18/12/2017 0:13Acquired1XYZ
18/12/2017 0:20Released-1ABC
18/12/2017 0:31Acquired1ADE
18/12/2017 0:31Released-1XYZ
18/12/2017 0:37Acquired1FBA
18/12/2017 0:38Released-1FBA
18/12/2017 0:41Released-1NRA
18/12/2017 0:41Acquired1NRA
18/12/2017 0:52Released-1ADE
1 ACCEPTED SOLUTION

Hi @gunner

 

Here it goes

 

Time Difference =
VAR TimeAtAcquisition =
    CALCULATE (
        FIRSTNONBLANK ( 'LicenseUsage'[Timestamp (UTC)], 1 ),
        FILTER (
            ALLEXCEPT ( 'LicenseUsage', 'LicenseUsage'[User] ),
            'LicenseUsage'[Action] = 1
        )
    )
VAR TimeAtRelease =
    CALCULATE (
        FIRSTNONBLANK ( 'LicenseUsage'[Timestamp (UTC)], 1 ),
        FILTER (
            ALLEXCEPT ( 'LicenseUsage', 'LicenseUsage'[User] ),
            'LicenseUsage'[Action] = -1
        )
    )
RETURN
    DATEDIFF ( TimeAtAcquisition, TimeAtRelease, MINUTE )

Regards
Zubair

Please try my custom visuals

View solution in original post

13 REPLIES 13

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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