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

How to know first and last record in a group for calculation purposes

edited February 2007 in End User
Hi,

I have a group band set up. Basically for each detailed record I am
creating a string (to be exported to a file). However, the first record of
the group nees to be prefixed with some control characters, and the last
record needs to be suffixed with some contril characters. What is the best
way to achieve this? I have tried a group count field to work out how many
records there are but it appears to increment itself as it goes through each
record (as opposed to showing the total number in the group - even using
lookahead).

Thanks

Alex

Comments

  • edited February 2007
    Hi Alex,

    ReportBuilder does not have any built-in feature to pre-count the number of
    records in a group. One option might be to create a two pass report and in
    the first pass, keep track of what record each group breaks on. Perhaps
    using the AfterGroupBreak event of the group or the
    GroupFooterBand.BeforePrint event. Then you can use this information during
    the second pass to determine the first and last record of a group.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2007
    K will give that a go

    Alex

  • edited February 2007
    Hi,

    Not sure how this would work. In the first pass are you saying keep an
    array for each group break of what the recordcount was? If I had a thousand
    group breaks thats a big array (especially to use with ReportBuilder where
    calculations are slow). Or am i misinterpreting?

    Just out of interest, how then would you handle the need t display
    percentages, for example the percentage each group represents in percentage
    terms out of the total. Is this not supported?

    Regards

    Alex

  • edited February 2007
    Hi Alex,


    Yes this is what I was suggesting. As I mentioned before, ReportBuilder
    wasn't designed to know how many records are in each group. It is easy to
    alter the first record of a group using the AfterGroupBreak but the problem
    lies with the last record of a group. All group events fire after this band
    has been created.

    As an alternative, you might try making changes to the components during the
    first pass of the report using the group events (you will have to experiment
    with different events to see if they fire at the proper time) so those
    changes are reflected during the second pass.

    I believe constructing a list of where each group will break is a more
    elegant solution and will be easier to manage.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2007
    Hi Nico,

    Seems very limiting to not be able to calculate running percentages in a
    report-writing tool, but lets work with that limitation. I need to know
    then how do you create an array, I didnt think ReportBuilder supported array
    type variable definitions.

    Thanks

    Alex
  • edited February 2007
    Hi Alex,

    Keeping a running percentage of a group is very different from adding
    control characters to the last detail of a group. :). Perhaps I have
    missunderstood what you were trying to accomplish from the beginning.

    http://www.digital-metaphors.com/tips/percentage.zip


    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2007
    Hi Nico,

    I used the running percentage example as I envisaged that if you can do this
    then you have a total count to also be able to identify the last record in a
    group.

    That percentage example, I tried it but it just kept calculating thousands
    of pages. Is it for a particular RB version, we currently are requiring
    this for V7? Also, is this an end-user report, can what you have done there
    be achieved purely using the end-user capability?

    Thanks

    Alex

  • edited March 2007
    Alex,

    Unfortunately we do not have an example that calculates percentage that
    support RB 7. If you take a look at the code of the example you can see
    that since the LookAhead property is set for the DBCalc components, these
    values will be calculated during the first pass, and then can be used to
    compare against the field value during the second pass. This bypasses the
    need to know when the group starts or ends. In your case, needing to change
    the value of certain components based on the total value, you could use the
    same method however you still need to know where the last detail in the
    group is going to be because you cannot change it once it has been
    generated. This is why you will need to keep track of where these group
    breaks are by either using the method I described before or perhaps manually
    looking ahead in the data using the pipeline routines.

    It is possible to create something similar to the total percentage example
    completely in RAP if you would like to keep everything in an end-user app.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

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