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

Trobleshooting formula w/variable from subreport 1

Status
Not open for further replies.

keithm2008

Programmer
Feb 27, 2009
9
CR2008 & btrieve(Peachtree)
I am producing a report that shows A/R amount, billing amount and calculating a % from those values, grouped by customer. A/R amount comes from main report using customers and jrnlhdr tables. Billing amount comes from a subreport using customers and ticket tables. Subreport is linked using customerId. Reports are produced in a given date range and that range is passed to the subreport as well. I have a shared variable VarBillAmt defined in both reports - to be used in my formula for calculating Percent of billing. The main report shows the correct values for both A/R Amount and billing amount, but when I use the values in a formula (@Pct of Billing) the results are way off. I've included some the report below for reference.

FYI - i have tried simplifying by adding the values and still get similar unexpected results.

Hope this lines up correctly...

section customerId A/R Billing Ticket Amount % Billing
GH1a Allison
GH1b
D Allison 950.00
D Allison 1,100.00
D Allison 1,100.00
GF1a Allison 3,500.00 6,100.00 <-from subreport
GF1b 24.18 <- @VarBillAmt; should be .52


@VarBillAmt is in GF1b; if I put it in GF1a i get a divide by 0 error.


Formulas with some comments added for some(?) clarity:

@Pct of Billing
local numbervar PctBilling;
PctBilling := (Sum ({JrnlHdr.MainAmount}))/{@VarBillAmt}
//3,500.00 = (Sum ({JrnlHdr.MainAmount}))
//6,100.00 = @VarBillAmt

@VarBillAmt
shared numbervar VarBillAmt;
//variable from subreport

@Reset VarBillAmt
whileprintingrecords;
shared numbervar VarBillAmt := 0;
//used in GH1A
 
I think the 24.18 must be the {@Pct of Billing} result. For one thing, your formula should be:

@Pct of Billing
local numbervar PctBilling;
shared numbervar VarBillAmt;
PctBilling := (Sum ({JrnlHdr.MainAmount},{table.customerID}))/VarBillAmt

...since you want the sum per that account to be divided. I also generally use the variable itself, not the formual containing the variable.

-LB
 
Also make sure the formula using the shared variable is in a section after the subreport. Subreports are processed after the formulas in a section, so could the formula be using the previous value from the subreport?

Use Section a/b/c to put the subreport in a section above the formula.

Use Underlay to display the sections at the same vertical position on the page.

Editor and Publisher of Crystal Clear
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top