Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
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
Medium Priority
440 Views
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
Question by:jaguar5554
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 35

Expert Comment

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

Rey Obrero (Capricorn1) earned 1000 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 35

Assisted Solution

Dan Craciun earned 1000 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

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

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
###### Suggested Courses
Course of the Month10 days, 11 hours left to enroll