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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
bergen288
Helper IV
Helper IV

Use DATEDIFF function to calculate session gap between previous end time and current start time

I have a table visual as shown below where Created_TS is the session start time and Created_TS_End is session end time.  I would like to use DATEDIFF function to calculate session gap between previous end time and current start time for each row as shown in 2 red box below after the data is sorted by Created_TS.  Is there an easy way to do it?

 

bergen288_0-1682105573314.png

 

2 REPLIES 2
bergen288
Helper IV
Helper IV

My data is pretty large one over 710,000 rows.  It takes very long time to create the new column (still waiting for it).  I believe a measure should have a much better performance as it will be used with a selected case via drill-through.  So I tried to define the following measure, but it gives me an error.  The root cause should be the 1st row which won't have previous (earlier) value.  How to address it?

 

Thanks.

bergen288_0-1682343299471.png

 

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but I tried to create a sample pbix file like below.

Please chech the below picture and the attached pbix file.

It is for creating a calculated column.

 

Jihwan_Kim_0-1682113318186.png

 

Expected result CC =
VAR _prevstart =
    MAXX (
        FILTER ( Data, Data[Created_TS] < EARLIER ( Data[Created_TS] ) ),
        Data[Created_TS]
    )
VAR _prevend =
    MAXX ( FILTER ( Data, Data[Created_TS] = _prevstart ), Data[Created_TS_End] )
VAR _start = Data[Created_TS]
VAR _diffinminutes =
    DATEDIFF ( _prevend, _start, MINUTE )
RETURN
    _diffinminutes

 

 

 


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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.