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!

simple formula but my syntax is wrong.

Status
Not open for further replies.

nervous2

IS-IT--Management
Feb 24, 2003
125
CA
I apologize for the question but staring at a screen for too long can make your head feel hollow.

Trying to run a comparison on 2 DB and list the number on a report,

I want to tell the report DB1 + DB2 / 2

this way i have the average of DB1 and DB2 this is working.

now problem is some the information in DB1 is missing and also in DB2
so I want to say
if DB1 >0 then DB2 and if DB2 > 0 then DB1

Here is my formula

If {CDNITEM.Specgrav} < 0 then {USAITEM.Specgrav} else
if {USAITEM.Specgrav} < 0 then {CDNITEM.Specgrav}
else
If {CDNITEM.Specgrav} > 0 and {USAITEM.Specgrav} > 0 then
({CDNITEM.Specgrav} + {USAITEM.Specgrav}) / 2

Now I think I realize why this is not working.

There are no errors in the formula, but the fields are not ")" they are blank instead therefore how so I state this formula but instead of using 0 i want to use (blank)

Thanks

 
correction

"here are no errors in the formula, but the fields are not ")" they are blank instead therefore how so I state this formula but instead of using 0 i want to use (blank)"

oops should read.

"0"
 
if not isnull({CDNITEM.Specgrav}) and
not isnull({USAITEM.Specgrav}) then
({CDNITEM.Specgrav} + {USAITEM.Specgrav}) / 2

This would return a zero if one of the fields was null.

Or do you really mean you want to show the value of the non-null field if the other field is null? If so, then use these formulas:

//{@cdn}:
if isnull({CDNITEM.Specgrav}) then
{USAITEM.Specgrav}

//{@usa}:
if isnull({USAITEM.Specgrav}) then
{CDNITEM.Specgrav}

//{@ave}:
({@cdn}+{@usa})/2

-LB
 
I think you want the following:

Code:
If isnull({CDNITEM.Specgrav}) or {CDNITEM.Specgrav} < 0 
then 
   {USAITEM.Specgrav} 
else
   if isnull({USAITEM.Specgrav}) or {USAITEM.Specgrav} < 0 
   then // 
      {CDNITEM.Specgrav}
   else
      ({CDNITEM.Specgrav} + {USAITEM.Specgrav}) / 2

Hope that helps

Steve Phillips, Crystal Reports Trainer & Consultant
 
Thank you all for the help. I'm 99.8 % complete with this report, one more issue which I need to approach.

Here is my formula

If isnull ({@CDN fill Level Conversion}) or {@CDN fill Level Conversion} < 0
then {@Spec Gravity to Lbs} else
{@CDN fill Level Conversion}


Basically I want to say if this "@CDN fill Level Conversion}" conversion is blank or < 0 then put in this equation {@Spec Gravity to Lbs} (so far this works)

but the end "else" is the problem,

I want to say if it's not <0 or null then put in the {@CDN fill Level Conversion}.

When I put this formula in the error states.

A string is required here and highlights ({@CDN fill Level Conversion})

What am i doing wrong? If I put in text instead and not a formula ('text') it works.


Thank you both for the help.

 
YOu can not have mixed data types in a If Then Else

Change to

If isnull ({@CDN fill Level Conversion})
or {@CDN fill Level Conversion} < 0
then {@Spec Gravity to Lbs}
else
toext({@CDN fill Level Conversion})

Ian
 
Nervous2,

Ian said:
toext({@CDN fill Level Conversion})

Ian meant to say:
ToText({@CDN fill Level Conversion})
[smile]

Cheers!

Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
This worked thank you!

Report is now complete. Much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top