Solved

Compare and calculate the number of days between records (date field), and resetting the compare/calculation for each unique ID

Posted on 2014-01-23
4
405 Views
Last Modified: 2014-01-23
Hello, Assistance with comparing and calculating the number of days between records, then resetting for each unique ID is much needed! Example:
P-ID      I-ID      TestDate            Difference
1      100      3/2/2012                      0
2      101      2/14/2012      0
3      102      2/29/2012      0
4      103      8/29/2012      0
5      104      8/20/2012      0
5      105      10/25/2012      66
6      106      2/29/2012      0
6      107      2/29/2012      0
7      108      7/20/2012      0
8      109      7/11/2012      0
9      110      4/3/2012                      0
10      111      9/11/2012      0
11      112      8/7/2012                      0
12      113      3/5/2012                      0
13      114      1/24/2012      0
14      115      3/19/2012      0
15      116      1/17/2012      0
16      117      4/6/2012                      0
16      118      6/13/2012      68
17      119      2/14/2012      0
18      120      10/2/2012      0
19      121      1/25/2012      0
19      122      5/4/2012                      24

My data source is an unupdatable query. Much thanks in advance!!
0
Comment
Question by:jaguar5554
  • 2
4 Comments
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39804955
See attached Excel file.
Basically it checks if 2 consecutive values in the first column are equal, it calculates the no of days between the dates in the 3rd column.

HTH,
Dan
Q-28346839.xlsx
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 250 total points
ID: 39805000
try this query


SELECT urTable.[p-id], urTable.[i-id], urTable.testDate, DateDiff("d",(select min(b.testDate) from urTable as B where B.[p-id]=urtable.[p-id] and b.[i-id]<=urtable.[i-id]),[testdate]) AS difference
FROM urTable;
0
 
LVL 34

Assisted Solution

by:Dan Craciun
Dan Craciun earned 250 total points
ID: 39805002
Btw, if you want to have more than 2 consecutive ID's, modify the formula as follows:

=IF($A2=$A3, DAYS($C3,$C2) + $D2,0)

Basically, this will add the number of days to the previous value, so in case of multiple identical IDs the last value will be the total number of days for that ID. If you only have max 2 consecutive IDs, then the formula is identical in function to the one in the sheet.
0
 

Author Closing Comment

by:jaguar5554
ID: 39805308
Experts! Both of the solutions work perfectly, and both deserve the full 500 points. Unfortunately, I am limited to only 500 points, so I gave the most I could to each (250 points). I selected the query as the best solution because I'm working in an MS Access database; however, the MS Excel solution will certainly be implemented into other of my data projects. Thank you Thank you Thank you.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question