Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: CR10 Display Top N based on condition Post Reply Post New Topic
Author Message
cbaz
Newbie
Newbie


Joined: 28 Jan 2014
Online Status: Offline
Posts: 2
Quote cbaz Replybullet Topic: CR10 Display Top N based on condition
     Posted: 28 Jan 2014 at 6:48am
Hello everyone -

I am building a report which displays an item number. Each item number will contain 1 to n location records. I want to display the item number and top two location records if the first location record equals a certain value and more then one location record is returned.

Currently, my report is grouped by item number and displays the top two location records. The top two records are displayed using a running total count which is reset for each item number(group). In the section expert under suppress I input a formula {Top2} > 2.

But I can not figure out how to suppress an entire group if the first returned location record does not meet certain criteria or if only one location record is returned.

Any suggestions or help would be appreciated!

TIA -
Crystal
IP IP Logged
kostya1122
Senior Member
Senior Member
Avatar

Joined: 13 Jun 2011
Online Status: Offline
Posts: 475
Quote kostya1122 Replybullet Posted: 28 Jan 2014 at 8:39am
you could try something like
for records with 1 location
in report tab select expert group place
count(location,item number)>1

not sure how you determine top location
if you have a sequence number per item number for location
you could write a formula like
formula
if certain criteria and sequence = 1 then location
else "a.error"
then just add to the group select expert
count(location,item number)>1 and
maximum(formula,item number) <> "a.error"

Edited by kostya1122 - 28 Jan 2014 at 8:40am
IP IP Logged
cbaz
Newbie
Newbie


Joined: 28 Jan 2014
Online Status: Offline
Posts: 2
Quote cbaz Replybullet Posted: 28 Jan 2014 at 10:27am
Thanks for your response! I have the report displaying the first two location records based on a desired criteria. At this point, I am leaving item numbers with one location record but I am sure the code below could be easily modified for that desired output. This is what I did:

1. Create this formula and put in the group header section.

@HideHeader
whileprintingrecords;
numbervar x := 1;
numbervar y := 0;

2. Create this formula and put it in the detail and footer section

@HideDetailFooter
whileprintingrecords;
numbervar x;
numbervar y;

if (x=1 and myTable.myField <> "MyCriteria") then
y := y + 1 else y;
x := x + 1;
y

3. I created a running total on the field I am grouping by. I am getting the count for each record which resets on change of group. I called this Top2.

4. In Details > Section Expert > Suppress (do not check) > Formula > Add

if {@HideDetailFooter} = 0 then
{#Top2} > 2 else
{@HideDetailFooter} = 1;



TIA -
Crystal
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