Comparing to date in previous record (1 Viewer)

froggiebeckie

Registered User.
Local time
Yesterday, 22:41
Joined
Oct 11, 2002
Messages
104
I've been capturing data on PMs, that are due at specific frequencies. This data includes the date performed.

Now I've been asked to provided data on how well we've held to the schedule, so I need to compare the date completed to the previous date completed.

Simplified, I have records like this a COMPLETED PM table, going back over several years.

ID1 Machine A: Completed 01/01/17
ID2 Machine A: Completed 06/01/17
ID3 Machine B: Completed 02/01/17
ID4 Machine B: Completed 08/01/17

I have a query that pulls all of these records, grouped by Machine.
How can I compare the date in record 2, to the date in record 1, to determine the number of days between the two dates?

Got a feeling this isn't all that complicated, but I'm just stuck.

Hope someone can aim me in the right direction.

Thanks,
BeckieO
 

plog

Banishment Pending
Local time
Yesterday, 21:41
Joined
May 11, 2011
Messages
11,643
Ultimately, with a DateDiff(https://www.techonthenet.com/access/functions/date/datediff.php). However, you are going to need to find out the prior date for each record. For that you have 2 options:

1. The easy way--with a DMax(https://www.techonthenet.com/access/functions/domain/dmax.php). You would find the nearest date before the one you are currently looking at.

2. The correct way--correlated subquery (https://msdn.microsoft.com/en-us/library/office/aa217680(v=office.11).aspx). This method involves writing a subquery in SQL to find the prior date in a similar manner to the DMax.

#1 is easier to write, but less efficient, so if this is a huge table I'd go with #2.
 

froggiebeckie

Registered User.
Local time
Yesterday, 22:41
Joined
Oct 11, 2002
Messages
104
Oh wow, thanks.
I didn't even think of DMax.
Thanks so much, I'll check out both links and see what I can do with them.

Again, thanks for the quick response.
 

Users who are viewing this thread

Top Bottom