?
Solved

Crystal Reports showing only 500 records and getting the average gross profit

Posted on 2014-12-17
7
Medium Priority
?
293 Views
Last Modified: 2014-12-18
I have  over 2,000 items but would like to only show 500 on the report and do an average gross profit.
The problem that I am having is that I am displaying only 500 records by using this code in the detail section: RecordNumber <= Count({INVENTOR.ITEM_ID}) - 500

When I do the summary it shows me the summary for all 2,000 items on report not the 500 items being printed.
I need help to show the gross profit on the 500 items on the report.

Thanks.
0
Comment
Question by:CarloVasquez
  • 3
  • 2
  • 2
7 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 40505428
DO you have 1 record per item?

Do you care which 500 show?

As you have found out summaries use all the records in the report not just the visible records.
You need to
1.  Create a selection filter that limits you to 500 items, consider using a TOP N query
2.  Create formulas that do the calculations rather than using the summary functions

Formula method
In the report header add a formula
WhilePrintingRecords;
Global NumberVar GrossProfit;
''

Open in new window


in the detail section or the section where you show the item information add a formula
WhilePrintingRecords;
Global NumberVar GrossProfit;
If RecordNumber <= Count({INVENTOR.ITEM_ID}) - 500 then
     GrossProfit := GrossProfit + {GrossProfit Field};
''

Open in new window


In the report footer add a formula to display the profit
WhilePrintingRecords;
Global NumberVar GrossProfit;
GrossProfit

Open in new window


If I read your supression correctly that is actually showing the first Count - 500 items or in your case with 200  it will show 1500

mlmcc
0
 

Author Comment

by:CarloVasquez
ID: 40505547
I am getting an error "A Boolean is required here" on the first code:

WhilePrintingRecords;
Global NumberVar GrossProfit;
''

I am putting this on the Report Header, Suppress, and click on x2 to enter code.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 40505713
No that should be a regular formula that is created then put on the report as a field in the report.

mlmcc
0
Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

 
LVL 35

Assisted Solution

by:James0628
James0628 earned 800 total points
ID: 40506721
mlmcc already asked this, but do you care which 500 records are used?

 Your suppression formula is suppressing anything before the last 500 records.  For example, if there were 600 records, it would suppress the first 100.  The test in mlmcc's second formula will need to be changed, but the specific test will depend on which records you want to include (first 500, or last 500).

 If you want to include the last 500, change <= to >.  Since the original test was deciding which records to suppress, and mlmcc's test is deciding which records to include, you need to reverse the test (change <= to >).

 Of course if you want to include the first 500 instead, you can just use RecordNumber <= 500.


 You also mentioned an average, and you'd need a count for that.  Assuming that the report could include fewer than 500 records, you'd need to check for that and use 500 or the actual record count, whichever was lower.  You could use Minimum ( [ Count ({INVENTOR.ITEM_ID}), 500 ]) to get that count.

 James
0
 

Author Comment

by:CarloVasquez
ID: 40506996
I did not get this statement:

'If I read your suppression correctly that is actually showing the first Count - 500 items or in your case with 200  it will show 1500'

Indeed I just want to add the first 500 records from highest to lowest. This I believe the sort will take care of, while delivering the report.  I just don't know where you get the 200 and show 1,500 in the above statement.  :/

Where would the Minimum ( [ Count ({INVENTOR.ITEM_ID}), 500 ]) formula go. To to the average what I am doing is hard coding the result that I have from mlmcc and divide that by 500. This would give me the average.
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 1200 total points
ID: 40507146
James is correct.  I forgot that was a suppression formula not a visible formula so my logic was backwards.

You only need James Minimum formula if you might have fewer than 500 records..  You use it as the divisor in the average calculation.  If you know you will always have at least 500 records to pick from, hardcoding the 500 will work.

The 200 in my statement should have been 2000.

James is correct that the test in my formula needs to be changes.  The calculation formula should be
WhilePrintingRecords;
Global NumberVar GrossProfit;
If RecordNumber > Count({INVENTOR.ITEM_ID}) - 500 then
     GrossProfit := GrossProfit + {GrossProfit Field};
''

Open in new window


mlmcc
0
 
LVL 35

Expert Comment

by:James0628
ID: 40507779
I think mlmcc has covered everything, but just ask if you still have any questions.

 James
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question