Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: How to subtract from 2 records Post Reply Post New Topic
Author Message
tampitt09
Newbie
Newbie


Joined: 23 May 2013
Location: United States
Online Status: Offline
Posts: 8
Quote tampitt09 Replybullet Topic: How to subtract from 2 records
     Posted: 09 Jun 2015 at 9:36am
Hello

suppose I have 2 records
          field1      field2    field3
record1    1.70        2.80      -3.90
record2    -1.70       3.00      -0.10

Difference   3.40      0.20      3.80
(this line is just summary of the other 2 records)


It looks easy from spreadsheet doing auto sum, but not sure how would CR would be able to handle this
Thanks
IP IP Logged
niha
Newbie
Newbie
Avatar

Joined: 05 Jun 2015
Online Status: Offline
Posts: 28
Quote niha Replybullet Posted: 09 Jun 2015 at 11:24pm
in formula u can use math function
Sgn(number) :-Return a number's sign.
<B>Sgn returns : 1 if number > 0, 0 if number is 0, and -1 if number < 0. </B>

if sign(proc.fieldname)=-1 then
sum:=(proc.fieldname)+next(proc.fieldname)
else
sub:=(proc.fieldname)-next(proc.fieldname)

basically u can use and modify as per your requirement


Edited by niha - 09 Jun 2015 at 11:35pm
IP IP Logged
tampitt09
Newbie
Newbie


Joined: 23 May 2013
Location: United States
Online Status: Offline
Posts: 8
Quote tampitt09 Replybullet Posted: 10 Jun 2015 at 2:27am
Hi there Niha

thanks for the tip, but I don't think it would work in this case since I'm adding the values from 2 records of SAME FIELD...anyways, looks easy and simple enough but still can't figure out the way to this yet

thanks again
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 10 Jun 2015 at 4:32am
If this is a straight sum then you can insert a summary (sigma sign) using the SUM for each field and set it ina group or report footer .
You can also create running totals that do the exact same thing.
 
perhaps it is your sample data that is confusing...?
If you are doing a sum I don't understand how
1.70 + (-1.70) = 3.40
or if you are subtracting how does
2.80 - 3.00 = .20 ?
 
My guess is that you are subtracting but you will need to clarify what you are doing, and if you have groups involved or if this is just one summary result for all rows in the report.
 


Edited by DBlank - 10 Jun 2015 at 4:33am
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