Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Custom Variables on a per-group basis

edited June 2016 in General


Hi,

First off, the important bits!

I am using RB 17.02 build 149, with Delphi XE.


I have a report which needs to perform some calculations on a per-group
basis, as well as maintaining values across the whole report for a
summary at the end of the report.

At its simplest, the report has a line for each item received (with a
timestamp field), and each line may (or may not) have a timestamp when
it is sent out again (if not sent out, then the field is '').
Additionally, a duration (in minutes) for each line is also provided
where the item has been despatched (else, it is '').

So, the fields in use essentially are:
Group Name
Item Name
Received
Despatched
Duration


I want the following in my group summary:

Count of items received
Count of items despatched
Average duration - where the item is despatched. This will be the
average of Duration for lines *only* where a Duration is set. A duration
of '' or '0' should not be used to perform the calculation.

I can use Count() for the first, but I do not believe I can use a Count
() or Average() for the final two because the Count() also include rows
where the value is '', and the Average() uses total record count as its
divider.

The report summary will show the same details, but of course from all
groups.


I have configured the following variables in Calc->Global->
Declarations->Variables:
NumItemsDespatched: integer; // Per-group count of items despatched
TotalItemsDespatched: integer; // Total count of items despatched
GroupTotalTime: double; // Per-group sum of duration
TotalTime: double; // Total sum of duration

Within each Detail band, I have a variable, which manipulates these
variables:

If (DBPipelineMaster['Duration'] > 0) Then
begin
NumItemsDespatched := NumItemsDespatched + 1;
TotalItemsDespatched := TotalItemsDespatched + 1;
GroupTotalTime := GroupTotalTime + DBPipelineMaster['Duration'];
TotalTime := TotalTime + DBPipelineMaster['Duration'];
end;
end;


In Group1AfterGroupBreak, I reset the per-group variables:

NumItemsDespatched := 0;
GroupTotalTime := 0;


This works perfectly for the group summary for the first group. And if
there is only a single group, the report summary is perfect, even with
Variable Height detail bands (which I know has been an issue looking at
some other topics on this group).


However, once there is a second group in the report, the subsequent
group summary, and therefore report summary are incorrect. The sum of
NumItemsDespatched for subsequent groups is higher than the number of
records, and this affects the calculation of the averages.

Although, if a subsequent group is only a single page of details, then
the values do appear to be correct for this group.

I can not see any immediate patterns (such as the incorrect values being
based upon the number of pages within the group), but the value does
vary based upon the number of pages per-group (which I tested by simply
changing the detail band height).


I appreciate this is quite a long post, with a lot of text, but I hope
that there may be something either immediately obvious, or that there is
enough information to at least begin to look into the issue.


Thanks

Garry Mitchell

Comments

  • edited June 2016
    Hi Gary,

    It appears you are using RAP. My first suggestion would be to get this
    working in Delphi initially so you can trace into the code and see each
    value updating real time. This may give you some clues for why certain
    values are incorrect. I would be especially interested in seeing how
    often the NumItems and TotalTime values are reset.

    Also be sure you are using the OnCalc of the variable to make
    calculations and that the variable is a numeric data type.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.