cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

## Date/Time Difference between ID

Dear Power BI Community

Following Task to solve:

Let's assume this table:

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
Community Support

Hi @qwertzuiop ,

``````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:

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.

3 REPLIES 3
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?)

Let me know if you need further information.

Thank you
Cheers qwertzuiop

Community Support

Hi @qwertzuiop ,

``````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:

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.

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - June 2024

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

#### Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors
Top Kudoed Authors