Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula based on a condition between two fields 2

Status
Not open for further replies.

VBugDenver

Technical User
Feb 18, 2011
16
US
I am creating a formula field in Crystal Reports. I have the formula named and am having trouble with the syntax. I need this to be a conditional formula and the result will be the time difference between a dates/time field based on a condition.

The fields are:

{Schedule App_DtTm} which returns a result like: 3/3/2011 12:00:00PM
{Schedule.Activity} with returns a result like: Simulation or Treatment

This is what I am trying to do:

I need to subtract {Schedule App_DtTm} where {Schedule.Activity} = “treatment” from {Schedule App_DtTm} where {Schedule.Activity} = “Simulation”

Any ideas?
 
I do not have crystal in front of me, so apologize for any errors, but thing you could create several formulas to evaluate and store data for calculations.

//{@Act_Tx_Assign}
datetimevar vtx;
IF {Schedule.Activity} = "treatment"
then vtx := {Schedule App_DtTm};

//{@Act_Sim_Assign}
datetimevar vsim;
IF {Schedule.Activity} = "Simulation"
then vtx := {Schedule App_DtTm};

//{@Subtract}
dtetimevar vtx;
datetimevar vsim;
vsim-vtx

//{@Act_Tx_Sim_Reset}
datetimevar vtx := (0,0,0,0,0,0);
datetimevar vsim := (0,0,0,0,0,0);


 
If you want to display the results in a group footer, you can use formulas like this:

//{@treatment}
if {Schedule.Activity} = "Treatment" then
{Schedule App_DtTm}

//{@simulation}:
if {Schedule.Activity} = "Simulation" then
{Schedule App_DtTm}

Make sure the case of the result matches what is in the field. Then create a third formula:

datediff("d",maximum({@treatment},{table.groupfield}),maximum({@simulation},{table.groupfield}))

Not sure what interval you want use "s" for seconds, "n" for minutes, "h" for hours.

This assumes there is only one treatment and one simulation per group.

-LB
 
LBASS, what worked perfectly, you are always a big help! My problem, and I do this often, is trying to build it all in one formula. This will help me tremendously! Thank you!
-John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top