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

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

Reply
STS_Joshua
Helper II
Helper II

DateDiff between filtered rows

Hi All,

 

I have a table like so:

TransIDModAtModByEventID
11:27:20 PMBobPick
11:26:59 PMBobPick
21:26:48 PMJillPick
31:26:24 PMHarryPick
21:25:39 PMJillPick
31:24:59 PMHarryPick
11:24:09 PMBobPick
21:23:27 PMJillPick
31:20:51 PMHarryPick

 

 

What I want to show is the time differences between each row with that changing dynamically as the table is filtered like so:

TransIDModAtModByEventIDTimeDiff(In Seconds)
11:27:20 PMBobPick21
11:26:59 PMBobPick11
21:26:48 PMJillPick24
31:26:24 PMHarryPick45
21:25:39 PMJillPick40
31:24:59 PMHarryPick50
11:24:09 PMBobPick42
21:23:27 PMJillPick156
31:20:51 PMHarryPick0

 

 

Then Filtered:

TransIDModAtModByEventIDTimeDiff(In Seconds)
11:27:20 PMBobPick21
11:26:59 PMBobPick170
11:24:09 PMBobPick0

 

 

Thanks!

2 ACCEPTED SOLUTIONS
jdbuchanan71
Super User
Super User

Hello @STS_Joshua 

Give this a try.

TimeDiff(In Seconds) = 
VAR CurrentRowTime = SELECTEDVALUE ( 'Table'[ModAt] )
VAR TimeSec = 
DATEDIFF (
    CALCULATE ( MAX ( 'Table'[ModAt] ),
        ALLSELECTED ( 'Table' ),
        'Table'[ModAt] < CurrentRowTime ),
    CurrentRowTime, SECOND )
RETURN
    IF ( ISBLANK( TimeSec ), 0, TimeSec )

DateDiffSec.jpg

View solution in original post

That's odd, the same change works for me:

TimeDiff(In Seconds) TransID = 
VAR CurrentRowTime = SELECTEDVALUE ( 'Table'[ModAt] )
VAR TransID = SELECTEDVALUE ( 'Table'[TransID] )
VAR TimeSec = 
DATEDIFF (
    CALCULATE ( MAX ( 'Table'[ModAt] ),
        ALLSELECTED ( 'Table' ),
        'Table'[ModAt] < CurrentRowTime,
        'Table'[TransID] = TransID ),
    CurrentRowTime, SECOND )
RETURN
    IF ( ISBLANK( TimeSec ), 0, TimeSec )

DateDiffSecGrouped.jpg

View solution in original post

6 REPLIES 6
jdbuchanan71
Super User
Super User

Hello @STS_Joshua 

Give this a try.

TimeDiff(In Seconds) = 
VAR CurrentRowTime = SELECTEDVALUE ( 'Table'[ModAt] )
VAR TimeSec = 
DATEDIFF (
    CALCULATE ( MAX ( 'Table'[ModAt] ),
        ALLSELECTED ( 'Table' ),
        'Table'[ModAt] < CurrentRowTime ),
    CurrentRowTime, SECOND )
RETURN
    IF ( ISBLANK( TimeSec ), 0, TimeSec )

DateDiffSec.jpg

Thanks for the answer, I have a followup though. Is there a way to display the DateDiff grouped for each order when unfiltered? Like so:

 

TransIDModAtModByEventIDTimeDiff(In Seconds)
11:27:20 PMBobPick21
11:26:59 PMBobPick170
21:26:48 PMJillPick24
31:26:24 PMHarryPick45
21:25:39 PMJillPick132
31:24:59 PMHarryPick248
11:24:09 PMBobPick0
21:23:27 PMJillPick0
31:20:51 PMHarryPick0

 

I tried changing your calculation some but did not get what I wanted:

TimeDiff = 
VAR CurrentRowTime = SELECTEDVALUE ( 'Table'[ModAt] )
VAR CurrentTransID = SELECTEDVALUE( 'Table'[TransID])
VAR TimeSec = 
DATEDIFF (
    CALCULATE ( MAX ('Table'[ModAt]),
        'Table'[TransID]=CurrentTransID,
        'Table'[ModAt] < CurrentRowTime ),
    CurrentRowTime, SECOND )
RETURN
    IF ( ISBLANK( TimeSec ), 0, TimeSec )

 

 

That's odd, the same change works for me:

TimeDiff(In Seconds) TransID = 
VAR CurrentRowTime = SELECTEDVALUE ( 'Table'[ModAt] )
VAR TransID = SELECTEDVALUE ( 'Table'[TransID] )
VAR TimeSec = 
DATEDIFF (
    CALCULATE ( MAX ( 'Table'[ModAt] ),
        ALLSELECTED ( 'Table' ),
        'Table'[ModAt] < CurrentRowTime,
        'Table'[TransID] = TransID ),
    CurrentRowTime, SECOND )
RETURN
    IF ( ISBLANK( TimeSec ), 0, TimeSec )

DateDiffSecGrouped.jpg

Sorry, but one last question. Is there a way to do that as a calculated column vs. a measurement? 

Sure, you can just add a column to your table and make it = the measure.

Column 2 = [TimeDiff(In Seconds) TransID]

DateDiffSecColumn.jpg

My mistake was replacing your ALLSELECTED filter in CALCULATE. With that in there it works. Thanks!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.