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
Irwan
Super User
Super User

Need Advice: How to Calculate Date Diff between Two Exact Event

Hello Power BI Experts,

I need an advice about my dataset.

 

Below is my data.

My need is to find the next row that contains the exact string (description) for example "replace" with the exactly same equipment number as both in yelow color below, then substract the date of that row with date of current row (yellow color). And the process continue until last row of data (next date of the data will be substract to previous date of the data).

Irwan_1-1687232143188.png

To make it simple, I want to calculate date difference between two events with exact description and equipment number.

 

Thank you and really appreciated for the help.

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

https://1drv.ms/u/s!AiUZ0Ws7G26RiQZUXnY1lqz0ovDw?e=ufVd4q

Screen Capture #1288.png

View solution in original post

10 REPLIES 10
Irwan
Super User
Super User

Hello @Ahmedx 

 

thanks, everything is working, got all my need to shape my database.

 

thank you and really appreciated for all the help.

Ahmedx
Super User
Super User

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

https://1drv.ms/u/s!AiUZ0Ws7G26RiQZUXnY1lqz0ovDw?e=ufVd4q

Screen Capture #1288.png

Hello @Ahmedx 

 

one last question, can we move the data in "Count of Days" into separate table or column accordingly to its "ID" and then sort it out in ascending order?

 

Thank you again.

hello @Ahmedx 

 

thanks, it moved to new table, however the days are summed in the new table according to ID. Is there a way not to sum the days in the new table?

 

the expected new table is going to be like this 

IDDay
6000000002638298
6000000002638377

 

and also is it possible to automatically sorted "day" column in ascending order after it moved to new table?

 

Thank you again, really appreciated for the help.

pls try this

Screen Capture #1295.png

Hello @Ahmedx 

 

It works perfectly.

 

Thank you and really appreciated for all the help.

Hello @Ahmedx 

 

thank you for the code, it works as my need.

 

Thanks again for the support.

Ahmedx
Super User
Super User

Share some data to work with (in a format the can be pasted in an MS Excel file) and show the expected result.

hello @Ahmedx ,

 

here is sample of the data to make it simpler.

The expected result is

1. 298 (from 16-Dec-19 till 9-Oct-20), days difference between line 2 and line 9.

2. 377 (from 9-Oct-20 till 16-Dec-19), days difference between line 9 and line 13.

Those three events have exactly same description and equipment number.

1600000001974Replace pulley8-Oct-19
2600000002638Replace motor16-Dec-19
3600000083190Replace pulley27-Jan-20
4600000002693Replace pulley12-May-20
5600000002616Replace pulley26-May-20
6600000083190Replace pulley6-Jun-20
7600000002638Replace pulley7-Jul-20
8600000003106Replace pulley21-Sep-20
9600000002638Replace motor9-Oct-20
10600000002693Replace pulley29-Jul-21
11600000002645Replace pulley19-Aug-21
12600000002624Replace pulley15-Oct-21
13600000002638Replace motor21-Oct-21

Thank you and appreciated with the help.

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