?
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
Medium Priority
?
451 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 35

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 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

by:Dan Craciun
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

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

864 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