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

OnCalc - Summary restrictions

edited March 2013 in RAP
Hi.

I have a simple subreport with a DBText (Count) and a DBCalc (Sum of Count)
and also a DBText that either is blank or contains a flag (string).
Based on the value of the flag I would like to omit records where the flag
has a given value in the summary of the (DBCalc).

How would I go about solving this using RAP?

Br
Petter

Delphi 2010
RB 14.05

Comments

  • edited March 2013
    Hi Petter,

    Before the summary band prints (Band.BeforePrint), check the value of
    the DB field tied to the DBText directly and then toggle the visibility
    of any other report components as needed.

    procedure SummaryBeforePrint...
    begin

    MyDBCalc.Visible := MyDataSet['MyFlagField'] <> '';

    end;

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2013
    Hi Nico

    In the context of my initial question, this is what I'm trying to
    accomplish:

    Count Flag
    1
    1
    1 1
    1 1
    1

    SUM of Count = 3

    Will the visibility of the DBText field affect the Sum of the DBCalc?

    Petter



    "Nico Cizik (Digital Metaphors)" skrev i nyhetsmeldingen: 5149bafc$1@mail.
    ...

    Hi Petter,

    Before the summary band prints (Band.BeforePrint), check the value of
    the DB field tied to the DBText directly and then toggle the visibility
    of any other report components as needed.

    procedure SummaryBeforePrint...
    begin

    MyDBCalc.Visible := MyDataSet['MyFlagField'] <> '';

    end;

  • edited March 2013
    Hi Petter,


    No, the DBCalc component accesses the dataset directly and is not tied
    to any other report component.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2013
    Ok Nico, how will your solution help me then?
    Can you explain?

    Petter

    "Nico Cizik (Digital Metaphors)" skrev i nyhetsmeldingen: 514b0834$1@mail.
    ...

    Hi Petter,


    No, the DBCalc component accesses the dataset directly and is not tied
    to any other report component.

  • edited March 2013
    Hi Petter,

    I'm very sorry, it appears I misunderstood your initial question. I was
    under the impression you simply wanted to hide a component when the
    field was blank.

    For this situation, I would not recommend using a DBCalc component.
    Instead use a Variable that calculates on Traversal. Inside the OnCalc,
    increase the value by one if the DB field is not blank essentially
    counting the non-blank records.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2013
    No Problem Nico - I'm quite impressed at your ability to understand the very
    complex situations and requirements described by some words...

    However I have failed to describe my case accurately enough:

    Count is a floating point value and The Flag is a String
    Iow, I really need to summarize the Count.
    But of course if I use a variable I could do any calculation....


    Count Flag
    1.5
    2
    2 R
    1 R
    3

    Sum 3.5

    Br
    Petter

    "Nico Cizik (Digital Metaphors)" skrev i nyhetsmeldingen: 514c5e0e$1@mail.
    ...

    Hi Petter,

    I'm very sorry, it appears I misunderstood your initial question. I was
    under the impression you simply wanted to hide a component when the
    field was blank.

    For this situation, I would not recommend using a DBCalc component.
    Instead use a Variable that calculates on Traversal. Inside the OnCalc,
    increase the value by one if the DB field is not blank essentially
    counting the non-blank records.

  • edited March 2013
    Hi Petter,

    Based on your specifications, shouldn't the below sum be 6.5 or am I
    still missing the problem?

    If you use a Variable of type Double to manually keep track of the Count
    sum, you should get the effect you are after. Note that even though the
    Variable is in the footer, the OnCalc will still fire for each record
    traversal. For instance, inside the Variable.OnCalc event...

    if DataSet['FlagField'] = '' then
    Value := Value + DataSet['CountField'];

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2013
    LOL - You are of course correct.

    Thanks for your help Nico.

    Petter

    "Nico Cizik (Digital Metaphors)" skrev i nyhetsmeldingen: 51504ec4$1@mail.
    ...

    Hi Petter,

    Based on your specifications, shouldn't the below sum be 6.5 or am I
    still missing the problem?

    If you use a Variable of type Double to manually keep track of the Count
    sum, you should get the effect you are after. Note that even though the
    Variable is in the footer, the OnCalc will still fire for each record
    traversal. For instance, inside the Variable.OnCalc event...

    if DataSet['FlagField'] = '' then
    Value := Value + DataSet['CountField'];

This discussion has been closed.