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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Calculate difference in minutes

I wanna know from the Datestamp coulmn see how much minute difference it's between the previous value and the last one.
I tried this formula below but got totaly different value.
 
Datediff = DATEDIFF(DataView[CommTimestamp];TODAY();minute)
 
The datestamp look like YYY-MM-DD-HOUR-MINUTE-SECOND
16 REPLIES 16
hnguy71
Super User
Super User

Is the column formatted as a Date type?



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
Anonymous
Not applicable

^^

yes it is.

Can you provide some sample data and your expected result?



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
Anonymous
Not applicable

sa.jpg

 

So that is that column, new data comes in every 5 min for each sensor and so on, but not alawys (sometime it drops or coming late) so I wanna make a new column to see how much it's difference between previous and the new datestamp by minutes.

Try this:

In a calculated column:

TimeDiff = 
var _PreviousTime = CALCULATE(MAX(Table2[CommTimeStamp]), FILTER(Table2, EARLIER(Table2[CommTimeStamp]) > Table2[CommTimeStamp]))
return
IF(ISBLANK(_PreviousTime), 0, DATEDIFF(_PreviousTime, Table2[CommTimeStamp], MINUTE))


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
Anonymous
Not applicable

I get this error:

 

The syntax for 'DATEDIFF' is incorrect. (DAX(var _PreviousTime = CALCULATE(MAX(DataView[CommTimeStamp]), FILTER(DataView, EARLIER(DataView[CommTimeStamp]) > DataView[CommTimeStamp]))returnIF(ISBLANK(_PreviousTime), 0. DATEDIFF(_PreviousTime, DataView[CommTimeStamp], MINUTE)))).

are you copying and pasting correctly?

 

TimeDiff = 
var _PreviousTime = CALCULATE(MAX(DataView[CommTimeStamp]), FILTER(DataView, EARLIER(DataView[CommTimeStamp]) > DataView[CommTimeStamp]))
return
IF(ISBLANK(_PreviousTime), 0, DATEDIFF(_PreviousTime, DataView[CommTimeStamp], MINUTE))


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
Anonymous
Not applicable

yes here u can see still error

te.png

I see that you still have a comma right before the DATEDIFF function. Also, double check to see if your CommTimeStamp column is indeed Data Type of DATE/TIME



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
Anonymous
Not applicable

the column are DATE/TIME already. I paste same code u wrote. but i works for u?

@Anonymous 

 

It definitely does.

 

formula.png

 

table.png



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
Anonymous
Not applicable

It's because u have another date format? also american? because I have 2019-04-19 13:33:22

it shouldn't matter. My original source for the date is exactly the same as yours. I'll upload the sample file for you to view:
https://1drv.ms/u/s!An8CCFsOzw0uc_OWSjBbUOCOgPk



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
Anonymous
Not applicable

now it works after small changes, thanks but is that possible that it gonna only filter from 10 May and after?  where in the code can I write it and how? because the data are huge and it's says ,

There's not enough memory to complete this operation. Please try again later when there may be more memory available.

 

If you're importing your data, you can filter from May 10th onwards. If you're using LiveConnection or from a database you can specify the filter ie,

 

SELECT * FROM db.MyDatabase WHERE CommTimeStamp >= '10/05/2019'



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
Anonymous
Not applicable

Can I use another instead for EARLIER? because it's earler that cause this memory problem. or do you have anyother soulation?

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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors
Top Kudoed Authors