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

Median, Uper And Lower Quartiles

edited November 2010 in RAP
How would I calculate the Mean, Median, Upper and Lower Quartiles for
the values of a particular field over a group and then over the whole
data set?

Comments

  • edited December 2010
    Hi Nigel,

    There is no built-in feature to make these calculations in ReportBuilder.
    You will need to make them manually using TppVariable components and their
    OnCalc events. Use the Timing property to determine when the event fires
    and the Reset property to determine when the value should be reset.

    http://www.digital-metaphors.com/rbWiki/Delphi_Code/Calculations/Overview

    Regards,

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

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited December 2010
    Ubnfortunately I can't get the Demos to work. It keeps complaining it
    can't get to c:\PDOXUSRS.NET


  • edited December 2010
    OK. Got the main RAP Demo to work. I am looking at Calculations Level 1
    - Retrieve Field Value.

    Value := plStock['Cur_Price'];

    Now what I would need to do is Create a dynamic array with one value for
    each record in the table, sort that array and then calculate the median
    for that.

    I don't see dynamic arrays in the Variable types under the language
    section so I am assuming this will not be possible.

    What I assume I will have to do is create a function in my Delphi code,
    register it as a user function and pass the data set in.

    e.g. function CalculateFieldMedian(ADateSet: TDataset; AFieldName:
    String): Double;

    and call it like so: CalculateFieldMedian(plStock, 'Cur_Price');

    1) What is plStock? A TDataset, TppDataPipeline?
    2) Can it be passed into a user function as a variable?
    3) What are the methods to iterate it's records and extract the field
    value for each one?




  • edited December 2010
    OK. I got the median working by using a passthrough function and a variable.

    function GetFieldMedian(ADataSet: TDataSet; AFieldName: String): Double;

    Using the RAP Demo I create a second variable call it like so:

    Value := GetFieldMedian(plStock.DataSource.DataSet, 'Cur_Price');

    Trouble is only one row of the DataSet shows on the report. If I don't
    call the median function they all show.


  • edited December 2010
    Hi Nigel,

    Are you perhaps altering the dataset in your Median routine? If so you need
    to remember that ReportBuilder is also trying to access this dataset so
    altering it can cause the report engine to malfunction.


    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.