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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Markus44
New Member

Date difference (minutes) between date stamps in different rows

Hello Community,

 

I have a case to which I can find plenty of information in this community, however, I am still not able to solve it. I am quite new to Power BI DAX formulas so sorry for that possibly stupid question.


My case:

 

I have many rows with individual date time stamps.

Each row also has a column namend "currentCount" as well as a column named "prevCount".


So it kinda looks like this:

 

IDcurrentCountprevCountdatetimestampDifference
154dd/mm/yyyy hh:mm:ss 
232dd/mm/yyyy hh:mm:ss 
365dd/mm/yyyy hh:mm:ss 
421dd/mm/yyyy hh:mm:ss 
543dd/mm/yyyy hh:mm:ss 

 

What I am looking for is the time difference in minutes between the currentCount and the prevCount.


From my research I assume it will somehow work using EARLIER, but as this is my first time using it I am having a hard time.

 

Hope my direction is correct and someone can help me out.

 

Thanks in advance and regards

Markus

 

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @Markus44 -No worries, you're on the right track, but using EARLIER might not be necessary for this case. Instead, you can compute the time difference between each row's datetimestamp in minutes directly using DAX without EARLIER

 

create a calculated column for the time difference in minutes

TimeDifferenceInMinutes =
VAR CurrentRowTimestamp = 'timedin'[datetimestamp]
VAR PreviousRowTimestamp =
    CALCULATE(
        MAX('timedin'[datetimestamp]),
        FILTER(
            'timedin',
            'timedin'[currentCount] = EARLIER('timedin'[prevCount])
        )
    )
RETURN
IF(
    NOT ISBLANK(PreviousRowTimestamp),
    DATEDIFF(PreviousRowTimestamp, CurrentRowTimestamp, MINUTE),
    BLANK()
)
 

rajendraongole1_0-1728467796373.png

 

Hope this helps

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

2 REPLIES 2
Kedar_Pande
Super User
Super User

Make sure your table is sorted by the datetimestamp column in ascending order so that each row correctly follows the previous one.

Add a Calculated Column:

Time Difference (Minutes) = 
VAR CurrentRowDate = 'YourTable'[datetimestamp]
VAR PreviousRowDate =
CALCULATE(
MAX('YourTable'[datetimestamp]),
FILTER(
'YourTable',
'YourTable'[ID] < EARLIER('YourTable'[ID])
)
)
RETURN
IF (
ISBLANK(PreviousRowDate),
BLANK(),
DATEDIFF(PreviousRowDate, CurrentRowDate, MINUTE)
)


If this helped, a Kudos 👍or a Solution mark would be awesome! 🎉
Cheers,
Kedar Pande
Connect on LinkedIn

rajendraongole1
Super User
Super User

Hi @Markus44 -No worries, you're on the right track, but using EARLIER might not be necessary for this case. Instead, you can compute the time difference between each row's datetimestamp in minutes directly using DAX without EARLIER

 

create a calculated column for the time difference in minutes

TimeDifferenceInMinutes =
VAR CurrentRowTimestamp = 'timedin'[datetimestamp]
VAR PreviousRowTimestamp =
    CALCULATE(
        MAX('timedin'[datetimestamp]),
        FILTER(
            'timedin',
            'timedin'[currentCount] = EARLIER('timedin'[prevCount])
        )
    )
RETURN
IF(
    NOT ISBLANK(PreviousRowTimestamp),
    DATEDIFF(PreviousRowTimestamp, CurrentRowTimestamp, MINUTE),
    BLANK()
)
 

rajendraongole1_0-1728467796373.png

 

Hope this helps

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors