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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a Formula in Another Formula 1

Status
Not open for further replies.
Jun 17, 2010
58
US
Thanks to Gary Parker for his help getting the lastdate formula working properly for me in a whole lot less code too!

Being that I am a newbie at CR and have XIr2...I used this to call the LastDate formula and find the difference between it and the current date. It brings up 0s. What am I doing wrong? I just want it to display the difference either in the original LastDate or in this new formula. Preferably in this new formula

Formula: Days_Since_Last_Action
-----------------------------------

DateTimeVar LastDate;
numberVar Days_Since_Action;

If LastDate < CurrentDate then
Days_Since_Action :=DateDiff ("d", LastDate, CurrentDate);
 
We don't know how Last Date was calculated, and we would also need to know where Last Date is being displayed (what report section) and in what report section you are expecting to calculate this difference.

-LB
 
Both fields are located in the Details Section of the Report.

The code for LastDate is as follows:

Local DateTimeVar LastDate;

If not(isnull({CONTACT2.URIDATREC})) Then
LastDate := {CONTACT2.URIDATREC};

If not(isnull({CONTACT2.URODATREC})) and {CONTACT2.URODATREC} > LastDate Then
LastDate := {CONTACT2.URODATREC};

If not(isnull({CONTACT2.UDATERECD})) and {CONTACT2.UDATERECD} > LastDate Then
LastDate := {CONTACT2.UDATERECD};

If not(isnull({CONTACT2.USTATREP})) and {CONTACT2.USTATREP} > LastDate Then
LastDate := {CONTACT2.USTATREP};

LastDate
 
You have to define the variable the same way in both formulas:

[red]Local[/red] DateTimeVar LastDate;
numberVar Days_Since_Action;
If LastDate < CurrentDate then
Days_Since_Action := DateDiff ("d", LastDate, CurrentDate);

If it still doesn't work, you might need to change it to:

evaluateafter {@yourlastdateformula};
Local DateTimeVar LastDate;
numberVar Days_Since_Action;
If LastDate < CurrentDate then
Days_Since_Action :=DateDiff ("d", LastDate, CurrentDate);

-LB
 
The local declaration didn't fix the calculation.

Get an error saying ) is expected with this

evaluateafter (@Last_Date);
Local DateTimeVar LastDate;
numberVar Days_Since_Action;
If LastDate < CurrentDate then
Days_Since_Action :=DateDiff ("d", LastDate, CurrentDate);

If change to the below, it brings up error about remaining text not part of formula after the "evaluateafter" mark

evaluateafter {@Last_Date};
Local DateTimeVar LastDate;
numberVar Days_Since_Action;
If LastDate < CurrentDate then
Days_Since_Action :=DateDiff ("d", LastDate, CurrentDate);

 
You can't call a local variable from another formula you#ll need to refer to the formula itself

If {@LastDate} < CurrentDate Then
DateDiff ("d", {@LastDate}, CurrentDate)

or you could calculate this in a single formula

Code:
Local DateTimeVar LastDate;

If not(isnull({CONTACT2.URIDATREC})) Then
    LastDate := {CONTACT2.URIDATREC};

If not(isnull({CONTACT2.URODATREC})) and {CONTACT2.URODATREC} > LastDate Then
    LastDate := {CONTACT2.URODATREC};

If not(isnull({CONTACT2.UDATERECD})) and {CONTACT2.UDATERECD} > LastDate Then
    LastDate := {CONTACT2.UDATERECD};

If not(isnull({CONTACT2.USTATREP})) and {CONTACT2.USTATREP} > LastDate Then
    LastDate := {CONTACT2.USTATREP};

If LastDate < CurrentDate Then
    DateDiff ("d", {@LastDate}, CurrentDate)

you don't need to assign the result to days_since_action as this will be the result of the formula which can be referenced by other formulas if necessary

HTH

Gary Parker
MIS Data Analyst
Manchester, England
 
Oh, yes. Oops--regarding the local variable.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top