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
saanah2019
Helper II
Helper II

Subtract datetime from a column

Hi, so I have a datetime field in a column and I just want to create a new column/measure which subtracts the previous entry if the dates are the same.

 

I have time and I want to calculate the difference in mins.

timedifference (mins)
1/1/2018 5:00  
1/1/2018 5:3030 
1/1/2018 6:0030 
1/4/2018 6:00  
1/4/2018 6:4040 
1/6/2018 6:00  
1/7/2018 6:00  
1/7/2018 7:0060 
1/7/2018 7:3030 
1/7/2018 8:0535 
   
   
   
5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Try these calculated column formulas:

Date = INT(Data[time])

Diff = if(ISBLANK(CALCULATE(MAX(Data[time]),FILTER(Data,Data[Date]=EARLIER(Data[Date])&&Data[time]<EARLIER(Data[time])))),BLANK(),Data[time]-CALCULATE(MAX(Data[time]),FILTER(Data,Data[Date]=EARLIER(Data[Date])&&Data[time]<EARLIER(Data[time]))))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

thanks but how would i do this in Power BI?

Hi,

Ensure the Excel file is closed.  Open PBI desktop and go to File > Import > Excel.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
ChandeepChhabra
Impactful Individual
Impactful Individual

@saanah2019 

You can do this using Power Query

 

Capture.png

 

You can refer to solution in the excel file here

Anonymous
Not applicable

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.