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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How to get the difference between 2 date/time using measure

Hi Guys,

 

Newbie here,

 

Is there a way to create a measure to calculate the difference between 2 date/time.

 

I can't create a calculated column because my datasource is a streaming dataset.

 

Thank you for answering!

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @Anonymous 

as I can suggest, the column named [Duration] can not store Date Type, it stores Period that is not equal Dates

So, in your case you cane re-write @Greg_Deckler statement like

 

Measure = DATEDIFF(MAX([DateTime]), NOW(), MINUTE)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

9 REPLIES 9
Greg_Deckler
Super User
Super User

Measure = DATEDIFF(MAX([DateTime]),MIN([DateTime]),MINUTE) ? 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi @Greg_Deckler,

 

It has an error whenever I put it in the table or any visual.

Capture13.PNG

Hopefully you didn't just copy and paste that code, it was an example that would need to be modified to fit your situation. But, since you didn't provide much information I just made up column names and such.

 

Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi @Greg_Deckler ,

 

I've tried to modify it using the column names of my table and that's the error that occurs.

 

I wanted to calculate  the difference between the datetimestamp it was recorded and the current datetime for each row.

 

Below is my sample dataset

 

Capture19.PNG

 

Since it's a streaming dataset, I can't modify the columns and add a calculated column to compute for the difference of each row.

 

So is there a way that i can get the difference between each date/time stamps and the current date/time for each row without using calculated column?

 

Thank you @Greg_Deckler 🙂 Hope this helps for the clarification of my question.

az38
Community Champion
Community Champion

Hi @Anonymous 

as I can suggest, the column named [Duration] can not store Date Type, it stores Period that is not equal Dates

So, in your case you cane re-write @Greg_Deckler statement like

 

Measure = DATEDIFF(MAX([DateTime]), NOW(), MINUTE)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Hi @az38 ,

 

I am now able to view the result whenever I added it to the table, however, I think the result is not correct. Current time right now is 4/18/2020 10:26:00 PM and the duration results are way too far when I use the measure.

 

Here is the screenshot:

Capture21.PNG

 

Sorry to be so newbie right here. Hope you can understand.

 

Thank you so much!

az38
Community Champion
Community Champion

@Anonymous 

create and put into visual new measure

=NOW()

to debug this issue


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Hi @az38 ,

 

I've checked what you've said and notice that the NOW() function gives me an incorrect time based on my current time on my PC right now. How do i modify this ? I see some fix but it requires the use of power query however i can't use it right now because of the dataset that i am currently using. Is there any other way to fix this ? 

 

Thank you so much @az38 !

az38
Community Champion
Community Champion

@Anonymous
Do you really need to fix it if your users work with the server data and Date/time and see it in appropriate form?
The only way I see in your case - to change your machine timezone

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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