Hi Robert,
First off all, sort the records in descending order based on the database field you would like to summarize. For eg: if the report shows top 5 customers in US based on sales figures, then sort the report on sales figures in Descending order.
Next, create a formula and use this code:
WhilePrintingRecords; numbervar inc; numbervar top_n; inc := inc + 1; if inc <= 5 then //where 5 means top 5 top_n := top_n + {field_to_summarize}
Place the above formula on the Details section.
Create another formula to display the top n sums:
whileprintingrecords numbervar top_n;
Place this formula on the Report/Page Footer.
Now, if the report is already grouped on a database field, then create a formula to reset the variables as follows:
whileprintingrecords numbervar top_n := 0; numbervar inc := 0;
Place the above formula in the Group Header.
You may then place the formula that displays the sum in the Group Footer.
Hope this helps!
-Abhilash
You can use complex formulas with variables if you want to. But, try using a Running Total instead! They calculate after Top N has processed, so you will get only the values included in the Top N in the running total, and no complex formulas are requred!
- George -
Add a comment