Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: Group Records 1-20, 21-40 etc Post Reply Post New Topic
Author Message
chrisfaw
Newbie
Newbie
Avatar

Joined: 26 Apr 2016
Online Status: Offline
Posts: 13
Quote chrisfaw Replybullet Topic: Group Records 1-20, 21-40 etc
    Posted: 15 May 2016 at 11:54pm
Hi Experts

Is there a way I can group the first 20 records then records 21-40, 41-60 etc in the detailed section of a CR then sum the groups.

Regards

Chris
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 16 May 2016 at 4:05am
The only way I can think you can do it (never tried) is to make a formula that does a modulo on the rowcount, but still need to figure how to designate a group (manual running total?!?). 
IP IP Logged
Valert16
Groupie
Groupie
Avatar

Joined: 21 Mar 2016
Location: Spain
Online Status: Offline
Posts: 57
Quote Valert16 Replybullet Posted: 17 May 2016 at 6:51am
You can do it by using a shared variable as a counter and a formula that defines an interval of N records (20 in your case). Then you can group on this formula and modify the group in order to show a group name like "1 - 20", "21- 40", and so on. You can insert a summary to get the sum, average, etc. on each group. Follow these steps:

- Create a formula named "IntervalNumber". Use this code (CR syntax):

Global NumberVar Counter;
Local NumberVar Result;
Result := 1 + ((Counter )\20) + {Table.NumericField} * 0;
Counter := Counter + 1;
Result

Replace {Table.NumericField} by any numeric field in your table. This field is necessary to avoid an error when previewing the report.

- Create a group based on the @IntervalNumber formula. Change Group Options; select "Use formula as Group Name", click the "x+2" icon beside this option and type this code in the formula editor:

NumberVar Value2 := CDbl({@IntervalNumber}) * 20;
NumberVar Value1 := Value2 - 20 + 1;
ToText(CDbl(Value1) , 0, "") & " - " & ToText(Value2, 0, "")

This code shows the group name as "1 - 20", "21 - 40", etc.

If you use a parameter instead of the fixed value 20, you can get custom intervals of N records, being N the parameter value.

I'm not sure but I think this should work for any report.
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.047 seconds.