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
386 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
Comment Utility
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 119

Accepted Solution

by:
Rey Obrero earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This collection of functions covers all the normal rounding methods of just about any numeric value.
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now