Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Sum With Conditional Post Reply Post New Topic
Author Message
prideandhonor
Newbie
Newbie


Joined: 07 Feb 2008
Location: United States
Online Status: Offline
Posts: 3
Quote prideandhonor Replybullet Topic: Sum With Conditional
     Posted: 07 Feb 2008 at 7:43am
I'm trying to figure out how to get the sum of numbers, the numbers depend on what a field equals. Something like this if {AR_InvoiceHistoryDetail.ExtensionAmt}  = 100 then 60 else 30).
My goal:
i want the sum of... if AR_InvoiceHistoryDetail.ExtensionAmt = 100 then add 60 to the total, if AR_InvoiceHistoryDetail.ExtensionAmt = 50 then add 30.
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 07 Feb 2008 at 7:59am
You can create a manual running total. Something like this:
Global NumberVar TotalAmt;
if {AR_InvoiceHistoryDetail.ExtensionAmt} = 100 Then
    TotalAmt := TotalAmt + 60
Else If {AR_InvoiceHistoryDetail.ExtensionAmt} = 50 Then
    TotalAmt := TotalAmt + 30;

I cover all the details and give sample code for writing formulas in Chapter 7 of my book Crystal Reports Encyclopedia.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
prideandhonor
Newbie
Newbie


Joined: 07 Feb 2008
Location: United States
Online Status: Offline
Posts: 3
Quote prideandhonor Replybullet Posted: 07 Feb 2008 at 8:08am
Thanks for the reply. Now I'm just trying to figure out how to get it to display on the form. This is the first time I've ever written formulas for cr.
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 07 Feb 2008 at 11:39am
To display the value, just create another formula that simply returns the variable. You can put it anywhere on the form.
Global NumberVar TotalAmt;
//return the variable so that it can be printed
TotalAmt;

Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
prideandhonor
Newbie
Newbie


Joined: 07 Feb 2008
Location: United States
Online Status: Offline
Posts: 3
Quote prideandhonor Replybullet Posted: 07 Feb 2008 at 1:09pm
I greatly appreciate the help. Thanks for your time.
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 07 Feb 2008 at 2:15pm
Glad to help!
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
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