Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Sum custom columns in Crystal Post Reply Post New Topic
Author Message
masoud
Newbie
Newbie


Joined: 16 May 2012
Online Status: Offline
Posts: 2
Quote masoud Replybullet Topic: Sum custom columns in Crystal
     Posted: 16 May 2012 at 3:09am
Hi Dear

I have data Like:
 Price           PostPaid
 1000$          False
 2000$          True
 100$            True
 1500$          False
 20$              False
----------------------------
I need to show sum of price separately like this:

PostPaid : 2100$
PrePaid :   2520$ 

I Create Formula field and write code but the result is incorrect

Local NumberVar strLen := count({DataTable1.ID});
Local NumberVar result2 := 0;
Local NumberVar i := 0;

While i < strLen Do
(
   If  {DataTable1.PostPaid}  Then result2 := {DataTable1.Debit} + result2;

 i := i + 1;
);
result2;

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 16 May 2012 at 3:17am
all that this is doing is multiplying...ID has no bearing, that I can see,  on Debit.
 
If all of this data is in 1 big string, you need to split it into an array and access the array, or you can step through the string.
 
If the data is individual rows on the report, get rid of the loop and make the variables shared (or global)
IP IP Logged
Gurbs
Senior Member
Senior Member
Avatar

Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
Quote Gurbs Replybullet Posted: 16 May 2012 at 3:18am
what you could do, is create two extra formulas. These could look like

{@True)
if {dataTable1.PostPaid} = True then Price else 0
{@False}
if {dataTable1.PostPaid} = False then Price else 0

Place these in your report (you can suppress them)
And then create 2 formulas to sum them.
{@PostPaid}
sum({@True})
{@PrePaid}
sum({@False})
IP IP Logged
masoud
Newbie
Newbie


Joined: 16 May 2012
Online Status: Offline
Posts: 2
Quote masoud Replybullet Posted: 16 May 2012 at 7:54pm
Thanks a lot "Gurbs" Your Code work Correctly
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