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

If then else

Status
Not open for further replies.

wanzek1

Technical User
Jun 13, 2012
79
US
I have written this formula but it isn't evaluating the entire formula. Am I missing something?

if Sum ({JCCD.EstUnits}, {JCCD.Phase})=0

then -Sum ({JCCD.ActualHours}, {JCCD.Phase})

else if (Sum ({JCCD.ActualUnits}, {JCCD.Phase}) > Sum ({JCCD.EstUnits}, {JCCD.Phase}))

then (Sum ({JCCD.EstHours}, {JCCD.Phase})-Sum ({JCCD.ActualHours}, {JCCD.Phase}))

else if (Sum ({JCCD.EstHours}, {JCCD.Phase})=0)

then -Sum ({JCCD.ActualHours}, {JCCD.Phase})

else (((Sum ({JCCD.ActualUnits}, {JCCD.Phase})/Sum ({JCCD.EstUnits}, {JCCD.Phase}))*
Sum ({JCCD.EstHours}, {JCCD.Phase})))-Sum ({JCCD.ActualHours}, {JCCD.Phase})

Thanks!
 
Wanzek,

Your first and third IF clauses are the same, perhaps this is the reason for the formula not functioning properly? With a quick look, the paranthesis look okay, is Crystal Reports giving you an error, or is it not "making it" to a certain part of the IF and not evaluting it properly?

Hope this helps!

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."
 
The first IF clause is
if Sum ({JCCD.EstUnits}, {JCCD.Phase})=0

The second IF clause is
else if (Sum ({JCCD.EstHours}, {JCCD.Phase})=0)

They are difference because one is Estimated Units and the other is Estimated Hours.

Crystal is not giving an error. It is not making it to the end of the formula.
 
Then you have to look at the data and see what each if statement is really doing. If I have this issue then I either comment parts of the formula to see the intermediate results or take parts of the formula and put into another formula (just the parts) and see what kind of results I am getting.

I hope this helps.
 
*facepalm* Sorry Wanzek, I looked twice, and swore they were the same. oops!

As Kray suggested, splitting it into parts and checking the individual evaluations is a good test. Another would be to ensure your Sum()s can/do equal exactly zero (thinking of the event that something like 0.32 would appear as zero if formatted to no decimals, but isn't "actually" zero).

Another thing is to determine if your ordering is correct -- perhaps the second clause triggers each time you think clause three should be the case (or some such thing). Again, testing the individual IF's as thier own formula's should help identify nuances such as this.

Again, my apologies for not looking quite close enough the first time. I should definitely see things like that! [smile]

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."
 
Also as soon as Crystal encounters an IF which is true it stops and returns the corresponding then clasue

Ian
 
if Sum ({JCCD.EstUnits}, {JCCD.Phase})=0

then -Sum ({JCCD.ActualHours}, {JCCD.Phase})

Just a doubt. Is the - in front of the Sum in the 2nd line required?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top