Hi there, I use Crystal Reports XI. I have a question and need somebody help me.
I have to compare the dates (If under the same ID) to determine whether they can be combined to be one record or not. For example:
ID |
Date1 |
Date2 |
1111111 |
11/14/2007 |
11/23/2007 |
1111111 |
12/4/2007 |
12/11/2007 |
1111111 |
12/14/2007 |
12/23/2007 |
The IDs on the above table are the same. If the different of the second record’s date2 and the third record’s date1 is equal or within 3 days, we combine these two records.
Final result after combined second and third record:
1111111 |
12/4/2007 |
12/23/2007 |
However, in the following situation, my formula is not working.
ID |
Date1 |
Date2 |
1111111 |
11/9/2007 |
11/13/2007 |
1111111 |
11/9/2007 |
11/18/2007 |
1111111 |
11/16/2007 |
11/25/2007 |
My Result (Incorrect):
ID Date1 Date2
1111111 |
11/16/2007 |
11/25/2007 |
|
|
|
The correct result should be: (Which is combined these 3 records into one)
ID Date1 Date2
1111111 |
11/9/2007 |
11/25/2007 |
My formula for the Date1 is :
if RecordNumber = 1 then
Date1
else if ClientID = previous(ClientID) and
OrgID = previous(OrgID) and
DateDiff("d", previous(Date2), Date1) <= 3 and
previous(Date1) >= Date1 then
Date1
else if ClientID = previous(ClientID) and
OrgID = previous(OrgID) and
DateDiff("d", previous(Date2), Date1) <= 3 and
previous(Date1) < Date1 then
previous(Date1)
else if ClientID = previous(ClientID) and
OrgID = previous(OrgID) and
Date1 = previous(Date1) and
Previous(Date2) < Date2 then
Date1
else if ClientID = previous(ClientID) and
OrgID = previous(OrgID) and
Date1 = previous(Date1) and
Previous(Date2) >= Date2 then
previous(Date1)
else if ClientID = previous(ClientID) and
OrgID = previous(OrgID) and
Date1 < previous(Date1) and
Previous(Date2) < Date2 then
Date1
else if ClientID = previous(ClientID) and
OrgID = previous(OrgID) and
Date1 < previous(Date1) and
Previous(Date2) >= Date2 then
Date1
else
Date1
My formula for the Date2 is :
Previous(Date2) <= Date2 then
Date2
else if ClientID = previous(ClientID) and
OrgID = previous(OrgID) and
Date1 = previous(Date1) and
Previous(Date2) > Date2 then
Previous(Date2)
else if ClientID = previous(ClientID) and
OrgID = previous(OrgID) and
Date1 < previous(Date1) and
Previous(Date2) <= Date2 then
Date2
else if ClientID = previous(ClientID) and
OrgID = previous(OrgID) and
Date1 < previous(Date1) and
Previous(Date2) > Date2 then
Previous(Date2)
else
Date2
Could you please help me out? Thank you so much.