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

CR 11.0 Counting Formula

Status
Not open for further replies.

BillBrosius

Programmer
Jan 9, 2003
33
0
0
US
I am trying to find a way to "Count" all printed lines on a page. I can do this by using a formula like:

Whileprintingrecords;
numbervar Count:=Count+1;

I then put this formula in every section of the report and then have another formula in the page footer that zeros out the Count variable.

The problem is that I don't want suppressed items to be included in the "Count".

Any ideas how to approach this?
 
Dear bill...

Then use the same condition in your counter formula excpet with a not or <> not equals.

numbervar cnt := If {Table.Field} <> 'XYZ' then cnt + 1 else cnt;

cnt


Hope that helps,

ro

Rosemary Lieberman
rosemary-at-microflo.com, Microflo provides expert consulting on MagicTSD and Crystal Reports.

You will get answers more quickly if you read this before posting: faq149-3762
 
I need to tie it to a Suppression property at the Section level.

An example would be that I have a Group Footer that subtotals the details section. The Group Footer is Suppressed if the details section only contains one record.

As I am counting the "Lines", I don't want the Suppressed Group Footer to impact the "Count" formula.

...................................Line Count
Group Header 1.....................1
...Group Header 2..................2
.....Group Header 3................3
......Detail............................4
......Detail............................5
.....Group Footer 3................6
...Group Footer 2..................7
Group Footer 3.....................8

In the above example my "Count" formula counts each line. In this next example I have "Suppressed" Group Footer 3 because there is only one Detail record and I don't need to subtotal it on the report.

....................................Line Count
Group Header 1......................1
...Group Header 2...................2
.....Group Header 3.................3
......Detail.............................4
...Group Footer 2...................6
Group Footer 3......................7

The way it works now, the "Count" formula still counts the suppressed Group Footer 3 Section.

I need to count only the sections that are not suppressed. It is hard to explain.

Does that make sense?



 
Typo in last post. The last Group Footer should be Group Footer 1 in both examples. Sorry.
 
By the way, this is an effort to count the actual lines printed on a page so that I can force a page break after a predefined number is reached.
 
Create four formulas:

//{@resetpg} to be placed in the page header or footer:
whileprintingrecords;
numbervar linecnt := 0;

//{@resetgrp} to be placed in the group header AND the group footer:
whileprintingrecords;
numbervar cntwingrp := 0;

//{@cntwingrp} to be placed in the detail section:
whileprintingrecords;
numbervar cntwingrp := cntwingrp + 1;

//{@linecnt} to be placed in all group header/footer sections and the detail section:
whileprintingrecords;
numbervar linecnt;
numbervar cntwingrp;

if cntwingrp = 1 and
count({Orders.Customer ID},{Orders.Customer ID}) = 1 then
linecnt := linecnt else
linecnt := linecnt + 1;

-LB
 
Thanks LB, But....

I am a little confused about the last formula and the significance of the Count. Can the count be for any field in the report or is it supposed to be for a particular group?

Bill
 
In all cases in these formulas, the group refers to Group #3. I should have indicated that.

-LB
 
OK. I don't see how this will keep blank sections from being counted though.
 
It worked when I tested it. Did you try it?

-LB
 
I did and it still counts the suppressed sections. I will review my work and make sure it is right and get back to you. Can you step me through the logic of your design?

I have three Group Headers and three Group Footers. All detail records are printed, but some footers that contain subtotal calcs will be suppressed if there is only one detail record. I achieve this by using a counter within each group. If a group only has one item, the footer is suppressed. I need to prevent the suppressed footer and/or header from being included in the Linecnt variable.

Thanks for your help.

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top