Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: mulitple IF statements Post Reply Post New Topic
Author Message
bwsanders
Senior Member
Senior Member


Joined: 05 Sep 2012
Location: United States
Online Status: Offline
Posts: 177
Quote bwsanders Replybullet Topic: mulitple IF statements
     Posted: 18 Feb 2013 at 10:02am
I need to have multiple IF statements run against a field and I'm looking for the best way to do it.

this is what i have now but there is an error here.


ToText({ELaborDist.amount}, 2, "") +

If {ELaborDist.det} = 'E' Then
    {ELaborDist.amount}
End If +

If {ELaborDist.det} = 'D' Then
    {ELaborDist.amount} * -1
End If +

If {ELaborDist.det} = 'T' And {ELaborDist.cd} = 'D' Then
    {ELaborDist.amount}
End If +

If {ELaborDist.det} = 'T' And {ELaborDist.cd} = 'C' Then
    {ELaborDist.amount} * -1
End If;

any help would be greatly appreciated.
IP IP Logged
bwsanders
Senior Member
Senior Member


Joined: 05 Sep 2012
Location: United States
Online Status: Offline
Posts: 177
Quote bwsanders Replybullet Posted: 18 Feb 2013 at 10:21am
basically on the det field if it is an E then amount field needs to remain the same and if det is D then amount needs to be the opposite of sign ie negative if it's positive and vice versa.

the same logic would apply to last two if statements.
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 19 Feb 2013 at 3:52am
You can nest if statements, but I would probably use a Switch statement here.  It looks something like this:
Switch(
 {ELaborDist.det} = 'E', {ELaborDist.amount},
 {ELaborDist.det} = 'D', {ELaborDist.amount} * -1,
 {ELaborDist.det} = 'T' And {ELaborDist.cd} = 'D', {ELaborDist.amount},
 {ELaborDist.det} = 'T' And {ELaborDist.cd} = 'C', {ELaborDist.amount}*-1,
  true, 0)
 
-Dell
 
IP IP Logged
bwsanders
Senior Member
Senior Member


Joined: 05 Sep 2012
Location: United States
Online Status: Offline
Posts: 177
Quote bwsanders Replybullet Posted: 19 Feb 2013 at 3:57am
awesome, i'll have to see if that works. 
IP IP Logged
bwsanders
Senior Member
Senior Member


Joined: 05 Sep 2012
Location: United States
Online Status: Offline
Posts: 177
Quote bwsanders Replybullet Posted: 19 Feb 2013 at 4:02am
it absolutely works! i was piecing this together as your email came across and it looks like they both do the same thing. although i like your code better as it's cleaner.

shared numbervar Amount;

Amount := 0;

 

Select {ELaborDist.det}

    Case "E"

    : Amount := {ELaborDist.amount}

    Case "D"

    : Amount := Sum({ELaborDist.amount}) * (-1)

    Case "T"

    : (

        If {ELaborDist.cd} = "D" Then

            Amount := {ELaborDist.amount}

        Else

            Amount := -(Sum({ELaborDist.amount}))

        )


IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 19 Feb 2013 at 4:14am
And you don't need the variable - you could just put the value that you want to return after the colon and then do a final case of True that returns the zero.  It's probably not that big a deal except that variables add a bit of processing overhead so it's better to avoid using them if you don't specifically need them.
 
-Dell
IP IP Logged
bwsanders
Senior Member
Senior Member


Joined: 05 Sep 2012
Location: United States
Online Status: Offline
Posts: 177
Quote bwsanders Replybullet Posted: 19 Feb 2013 at 4:56am
well now that i have the numbers showing as they need to. i need to create 2 separate footers for the report.

one will show the sum for the amount where det = t and cd = d and the other will only run if it sees netcheck is >0.

i wrote the first footer but it doesn't seem to want to do the math. is there a certain place that i should put it or run it?

thanks so much for all of your help.
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 19 Feb 2013 at 7:10am
I would set these up as a pair running totals.  Set "Evaluate On" for each as a formula and you'll get the sums based on the conditions.
 
-Dell
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum