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

RunningTotal on formula using whileprintingrecords 1

Status
Not open for further replies.

Gus01

Programmer
Sep 4, 2009
45
FR
Hello,

I may be missing something?
In this faq :

I see:
"To summarize second-pass formulas, create running totals using variables and the WhilePrintingRecords function."

But the following formula @f1 can not be selected for RunningTotal [CR for .NET 2005], it's OK without whileprintingrecords:
@f1
whileprintingrecords;
{table.fld};

So, is it possible to use in the DetailSection the sum on a formula with whileprintingrecords ?

Thanks for help ...
 
No, you can't insert a sum on a formula that uses "whileprintingrecords". Inserted summaries happen at an earlier pass. What the faq was referring to was the ability to use variables to summarize formulas that are not available for inserted running totals or summaries. So what is it you are trying to summarize?

-LB
 
Thanks for the explanations !

In the DetailSection, I have the following formula to print the difference between a field and the previous value of the field :
@diff
whileprintingrecords;
numbervar prev;
numbervar curr;
prev := curr;
curr := {table.field}
curr - prev

in the GroupFooterSection, a sum on the @diff formula :
@totaldiff
whileprintingrecords;
numbervar total;
total := total + {@diff};
total;

and I try to print in the DetailSection the % of diff :

{@diff} / {@totaldiff}

but in that way, the @totaldiff is not complete ... ?
 
First, I provided you with the {@diff} formula for comparing group totals, not detail records. It's really unnecessary at the detail level. If used for groups, I should actually have suggested this:

whileprintingrecords;
numbervar prev;
numbervar curr;
numbervar diff := 0;
prev := curr;
if groupnumber = 1 then
curr := 0 else
curr := sum({table.field},{table.group});
if groupnumber = 1 or
{table.group} <> previous({table.group}) then
diff := 0 else
diff := curr - prev;
diff

For a detail level comparison though, you only need a formula like this:

//{@diff}:
if not onfirstrecord and
{table.group} = previous({table.group}) then
{table.field} - previous({table.field})

The problem you are running into is because the difference formula is based on sequential records, and therefore, the result isn't know until the footer level. To provide a percent at the detail level, you would have to save the report as a subreport, place it in the group header and then pass a shared variable containing the group total to the main report for use in the percentages.

-LB
 
OK, and thank you again.

I tried a subreport in HeaderSection and it works well.

How is it possible to hide this subreport?
If I put the 'suppress' option, or if I suppress the section, subreport is not running ... and I don't retrieve the values in the main report

 
Place the subreport in its own report header section (insert one if you need to). Then:

1-Suppress all sections WITHIN the subreport.
2-In the main report, select the subreport->right click->format subreport->subreport tab->check "suppress blank subreport".
3-While the subreport is selected->right click->borders->remove all borders.
4-In the main report->section expert->check "suppress blank section".

What you cannot do is suppress the subreport object or suppress the section it is in.

-LB
 
Perfect,
Thank you for all the advice !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top