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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
tameemyousaf
Helper I
Helper I

Difference Between Two Dates in Single Column

Hi,

I have data that has timestamp in sigle row. I want to calculate the difference (in seconds or minuites) between two timestamps and need to show in another column or measure. Can anyone please help. Below is the screenshot of data.

 

tameemyousaf_0-1623578560866.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @tameemyousaf ,

 

Check the formula.

Column = 
var lasttime = CALCULATE(MAX('Table'[timestamp]),FILTER('Table','Table'[timestamp]<EARLIER('Table'[timestamp])))
return
IF(ISBLANK(lasttime),BLANK(),DATEDIFF(lasttime,'Table'[timestamp],MINUTE))

2.PNG

 

Best Regards,

Jay

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @tameemyousaf ,

 

Check the formula.

Column = 
var lasttime = CALCULATE(MAX('Table'[timestamp]),FILTER('Table','Table'[timestamp]<EARLIER('Table'[timestamp])))
return
IF(ISBLANK(lasttime),BLANK(),DATEDIFF(lasttime,'Table'[timestamp],MINUTE))

2.PNG

 

Best Regards,

Jay

Fowmy
Super User
Super User

@tameemyousaf 

Can you explain with an example based on your sample data?

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy I need such type of results. The difference in seconds.

 

tameemyousaf_0-1623594784423.png

 

@tameemyousaf 

You can add the following New Column to your table to get the time difference in seconds.

Difference = 
var __datetime = Table20[Date] + Table20[Time]
var __predatetime = 
    MAXX(
        FILTER(
            ADDCOLUMNS(
                Table20,
                "@DateTime",
                    Table20[Date] + Table20[Time]
            ),
            [@DateTime] < __datetime
        ),
        [@DateTime]
    )
return
DATEDIFF( __predatetime,__datetime,SECOND )

Fowmy_0-1623598305143.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy Thanks for your reply. I have only one timestamp column. In this case what will be the value of _dateTime variable.

@tameemyousaf 

This should work:

Difference = 
var __datetime = Table20[DateTime]
var __predatetime = 
    MAXX(
        FILTER(
            ALL(Table20[DateTime]),
            Table20[DateTime] < __datetime
        ),
        Table20[DateTime]
    )
return
    DATEDIFF( __predatetime,__datetime,SECOND )




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@tameemyousaf 

you can try this

Column = 
VAR last=MAXX(FILTER('Table','Table'[Timestamp]<EARLIER('Table'[Timestamp])),'Table'[Timestamp])
return if(ISBLANK(last),0,round(('Table'[Timestamp]-last)*3600*24,0))

pls see the attachment below





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

Proud to be a Super User!




Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors