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

subtracting one formula from another

Status
Not open for further replies.

ssiroky

Technical User
Sep 4, 2003
17
US
I created two formulas to designate victims' age vs. offender's age. for example, and I did the same for offenders

if {INCIDENT_PEOPLE.ROLE_ROLE_TYPE} = "v" then ({INCIDENT_PEOPLE.APPROX_AGE}) else ""


Now I thought that I could just take the new field "offenders" and subtract the new field "victims" from it to get an age difference. But it gives me the error message of
"a number, currency amount, or date_time is required.

I'm not sure why I'm getting this error. Any ideas on simpler ways to create this? Thanks for any ideas!!
 
Your fields are strings and not numbers. If they were numbers you would get the "number, currency..." warning when you created this formula if {INCIDENT_PEOPLE.ROLE_ROLE_TYPE} = "v" then ({INCIDENT_PEOPLE.APPROX_AGE}) else ""

Crystal doesn't allow for mixed If then Else results. You can't have a string for the TRUE and a Number for the FALSE

Change your foumulas to:
if {INCIDENT_PEOPLE.ROLE_ROLE_TYPE} = "v" then tonumber({INCIDENT_PEOPLE.APPROX_AGE},0,"") else 0

You should now be able to subtract the two formulas




Mike
 
thanks for the help Mike....that worked!!
 
ok, now I'm running into a larger problem. Each person's age creates a new record. So I'll have a victim of 5 years old, and an offender of 25. This will generate two separate records. So when I go to subtract the victim from the offender, I get these type of results.

record 1
victim age = 5 offender 0 difference of -5

record 2
victim age = 0 offender 25 difference of 25

 
How do you know what victim and offender belong together? Is there an incidentID field? Then you would group on the incidentID, and then make your difference formula look like:

if {table.incidentID} = previous({table.incidentID}) then
{@offenderage}-previous({@victimage})

You would sort records by {INCIDENT_PEOPLE.ROLE_ROLE_TYPE} in descending order, assuming that offenders are coded as "o".

-LB

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top