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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
rogerdea
Helper IV
Helper IV

DateTime difference to previous date/time

I am trying to calculate the difference in minutes between the date/time values in my table, to end up with a new column called "Diff" like in the example below.

 

rogerdea_0-1662015550173.png

I looked at similar example but couldn't get these working due to extra fields being used whereas i'm hoping this is much simpler as its just one column with date and time in.

 

Can anyone show me what the DAX would be for this and if it should be a measure or calculated column?

 

Thanks

5 REPLIES 5
Anonymous
Not applicable

Hi @rogerdea ,

According to your descriptions, i guess you add a measure with @Fowmy  dax formula to table visual. if you want to show the date according to the filter, please add a new column to the original table, then add the datetime column to slicer visual.

 

Best regards,
Community Support Team_ Binbin Yu

Fowmy
Super User
Super User

@rogerdea 

Add the following DAX code in a new calculated column:

Diff in Minutes = 

VAR __CURRTIME = 'Table1'[DateTime]
VAR __LASTTIME = 
    CALCULATE(
        MAX('Table1'[DateTime]),
        'Table1'[DateTime]<__CURRTIME,
        REMOVEFILTERS('Table1')
    )
VAR __RESULT = 
    DATEDIFF( __LASTTIME, __CURRTIME , MINUTE )
RETURN
    __RESULT

Fowmy_0-1662016677482.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

Thank you @Fowmy 

 

I've applied that solution to my data but it's giving strange results, and i'm not sure why.  I've pasted the DAX with the actual real table names, have i applied the solution correctly?

Thanks

 

rogerdea_0-1662017753297.png

 

rogerdea_1-1662017876157.png

 

 

@rogerdea 

Did add a Measure or a Calculated Column ?

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 figured out why it wasn't working.  I had a filter on the data which the code ignores, so the DAX is actually fine.

 

Is it possible to remove the REMOVEFILTERS part and have it working so that the dates dynamically change according to what filters are being used?  I tried deleting that part but the calculation broke.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.