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
Fantastic_Raab
Regular Visitor

Datediff from nonconsecutive rows, group by category

Hello - I'm stumped finding the date difference between nonconsecutive rows, grouped by category.  ProjectID is the "category", I need to caculate the time in between the previous record and a newly created record is that has the same ProjectID.

Any help is greatly appreciated.  

2021-06-14 16_35_30-Window.png

3 REPLIES 3
Fantastic_Raab
Regular Visitor

Latest Attempt Using DAX:

 

 2021-06-15 11_46_34-Window.png

 

My concern is the PreviousDate value isn't finding the corresponding ProjectID. 

 

Thanks in advance!

selimovd
Super User
Super User

Hey @Fantastic_Raab ,

 

you can either do that already in Power Query:

Value from previous row – Power Query, M language – Trainings, consultancy (exceltown.com)

 

Or you can do that in DAX. Ther you could use EARLIER, what is not recommended, or what I usually prefer is to do it with variables. You find both approaches in the following article:

Cracking DAX – the EARLIER and RANKX Functions - Simple Talk (red-gate.com)

 

Then you just have to calculate the date difference between the two values with the DATEDIFF function and you got your result.

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

Hi Selimovd - 

 

Regarding the suggestion to add the previous value: I'm not sure how to grab the previous value from the same ProjectID.  And the ProjectID is not static, there will be new ones regularly.  Though I think the PowerQuery is the way to go:

2021-06-14 18_33_21-Window.png

 

I am cautoius about using the EARLIER function.  The article suggests serious lag time due to number of operations.

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.

Top Solution Authors