Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: help with variables please! Post Reply Post New Topic
Author Message
MuddlingThrough
Newbie
Newbie


Joined: 13 Jul 2009
Location: United Kingdom
Online Status: Offline
Posts: 2
Quote MuddlingThrough Replybullet Topic: help with variables please!
     Posted: 13 Jul 2009 at 8:04am
As a complete beginner to Crystal, with no training, I can't work out how to use variables. The problem is that I have a report reporting on customer contact cases and each case has 4 'event' records. I need to store the creation date from the second event record so that it can be subtracted from the creation date of the 4th event record thus giving an elapse time.
I can't work out how/where to store that date nor how to use it and it's further complicated by the fact that it's date fields.
Help please!! 
IP IP Logged
mrc161
Newbie
Newbie


Joined: 27 Dec 2007
Location: United States
Online Status: Offline
Posts: 19
Quote mrc161 Replybullet Posted: 13 Jul 2009 at 8:31am
I think you could start by creating two formulas:
 
Formula1 : if EventRecord=2 then Creation Date
Formula2 : if EventRecord=4 then Creation Date
 
Then create a 3rd formula :
 
Elapsed Time: Formula2 - Formula 1
 
You might need to group by the Customer Contact Cases and take the Maximum of each of the Formula1 and Formula2 and THEN write the Elapsed Time formula, but hopefully this will help get you started.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 14 Jul 2009 at 6:47am
First question, is each event record in its own row, or are all the events in one row...does the data look like:
id1 event1
id1 event2
 
or
 
id1 event1 event2
 
if the later, the mrc161 solution might work (only because of subtracting dates, I am not sure of)
 
If the former, that solution won't work.
 
first quick primer on variables. 3 types, local, global, and shared.  if you using a variable, just in the formula and don't need that value anywhere else use local, otherwise use shared.  Global isn't as global as shared. To 'create' a variable, just put in the formula: shared variabletype variableName.  Look in help to find the different variables names.  That is all there is to using variable...be careful, they are case sensitive. = test for equality, := assigns a value
 
Back to the solution if the events are not all in one row. You will need a group of some kind, probably by customer contact. then the standard 3 formulas should suffice. 1 in group header seting the variable to a value like:
shared datetimevar start:="1/1/1900";
shared datetimevar ending:="1/1/1900";
""//hides the calculations
 
1 in the details section like;
shared datetimevar start;
shared datetimevar ending;
if event=2 then start:={table.creationdate};
if event=4 then ending:={table.creationdate};
""
 
1 in the group footer like:
shared datetimevar start;
shared datetimevar ending;
if start="1/1/1900" or ending="1/1/1900" then
 0
else
 datediff(hour, start, ending)
 
hopefully this is along the right path.  You might want to try the subtraction for the dates or different value (days, minutes..look in help)
IP IP Logged
MuddlingThrough
Newbie
Newbie


Joined: 13 Jul 2009
Location: United Kingdom
Online Status: Offline
Posts: 2
Quote MuddlingThrough Replybullet Posted: 20 Jul 2009 at 3:30am
Many thanks to both you and mrc161. Haven't quite got it working yet but the ideas and the syntax etc. you've given me will certainly help and have pointed me in the right direction!
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum