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

Subtract two summed detail amounts

Status
Not open for further replies.

CanoWermz

Programmer
Apr 24, 2006
6
US
Hi again,

We are comparing ledgers. How do I subtract ledger 1 from ledger 2? Both rows are summed amounts in my detail section.
A summary would be great, but there is every option BUT subtraction. Willing to change it up if needed. What do the techs say?

PROJECT A Ledger 1 amount
PROJECT A Ledger 2 amount
I need difference of amount here

PROJECT B Ledger 1 amount
PROJECT B Ledger 2 amount
then we do it again and again and again

Thanks for the assist, Brian
 
What report section is each line in? Detail sections don't contain summaries unless they have been pre-calculated and returned as a field. Is "amount" a formula?

-LB
 
I say summed, because it is summed in Query Manager prior to getting to Crystal. I guess it doesn't really matter in my case, it is just an amount.

I did get it to work using the following. I do not always have 2 Projects though and that messes up my subtraction. Where should I reset the variables?

Suppressed formula on DETAIL line:

WhilePrintingRecords;
shared numbervar org_orig;
shared numbervar prj_orig;
If {Ledger} = '1' then org_orig := {amount} else
prj_orig := {amount};

Then in Project Group footer I have formula :
whileprintingrecords;
shared numbervar org_orig - shared numbervar prj_orig;

this seems to be working. Is there a better way?

thank you
 
What should happen if there are three ledgers in a group? What would be subtracted from what?

-LB
 
Two is the limit. Ideally we would have one ledger 1 and one ledger 2 per project, but sometimes we have 0 ledger 1 and a ledger 2 entry for a project.

PROJECT A Ledger 1 amount
PROJECT A Ledger 2 amount
difference (working fine)

PROJECT B Ledger 2 amount
difference (wrong, no value for ledger 1 amount, it rolls over from previous project I think)

PROJECT C Ledger 1 amount
PROJECT C Ledger 2 amount
difference (working fine)
 
WhilePrintingRecords;
shared numbervar org_orig;
shared numbervar prj_orig;
if not inrepeatedgroupheader then (
org_orig := 0;
prj_orig := 0
);

Place this in the project group header.

Note that you don't have to declare the variables as "shared" unless you are trying to share amounts between a subreport and a main report or between subreports. Doesn't hurt though.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top