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
qwertzuiop
Advocate III
Advocate III

Date/Time Difference between ID

Dear Power BI Community

 

Following Task to solve:

Let's assume this table:

 

qwertzuiop_0-1685966651182.png

We are looking for the date/time difference of an ID from the first to the last Occurence

 

Any ideas how to solve this problem?

Thank you very much for your contribution.

 

Cheers

qwertzuiop

1 ACCEPTED SOLUTION

Hi @qwertzuiop ,

 

Please try:

TimeDiff_from_FirstTime_to_LastTime = 
var _a = MAXX(FILTER(ALL('Table'),[ID]=SELECTEDVALUE('Table'[ID])&&[CheckOccurence]="FirstTime"),[Date/time])
var _b = MAXX(FILTER(ALL('Table'),[ID]=SELECTEDVALUE('Table'[ID])&&[CheckOccurence]="LastTime"),[Date/time])
return DATEDIFF(_a,_b,MINUTE)/(60*24)

Final output:

vjianbolimsft_0-1686626258602.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Mahesh0016
Super User
Super User

@qwertzuiop Please share your ENDOUTPUT in table for more understanding.

Hi @Mahesh0016 

Hopefully with this visualisation I can better represent my desired output.

It is not necessarily important that the output is in the corresponding line. What is important is that somewhere there is information that, for example, ID MDY5MP takes approx. 3,999 days from first to lasttime (maybe best approach in a measure, no?)

 

qwertzuiop_0-1685970597452.png


Let me know if you need further information.

Thank you
Cheers qwertzuiop

Hi @qwertzuiop ,

 

Please try:

TimeDiff_from_FirstTime_to_LastTime = 
var _a = MAXX(FILTER(ALL('Table'),[ID]=SELECTEDVALUE('Table'[ID])&&[CheckOccurence]="FirstTime"),[Date/time])
var _b = MAXX(FILTER(ALL('Table'),[ID]=SELECTEDVALUE('Table'[ID])&&[CheckOccurence]="LastTime"),[Date/time])
return DATEDIFF(_a,_b,MINUTE)/(60*24)

Final output:

vjianbolimsft_0-1686626258602.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.