home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / tech91.zip / TI789.ASC < prev    next >
Text File  |  1991-08-26  |  7KB  |  265 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Paradox                                NUMBER  :  789
  9.   VERSION  :  3.0 & up
  10.        OS  :  DOS
  11.      DATE  :  August 26, 1991                          PAGE  :  1/4
  12.  
  13.     TITLE  :  Calculating Percent of Total in a Report
  14.  
  15.  
  16.  
  17.  
  18.   In order to do percentage totals, such as the value in the
  19.   Quantity field for the current record divided by the sum of all
  20.   the values in the Quantity Column, your computer must know both
  21.   values in the division.  In Paradox (or other software) terms
  22.   this means the sum of an entire group or column must be known at
  23.   print time.  The column total is determined by reading all of the
  24.   records while accumulating the total and then holding that total
  25.   in memory storage for later use.  At print time a second pass or
  26.   read of the records is done listing data according to the
  27.   report's design.  We call this process of reading once for
  28.   accumulators and a second time for printing a "two-pass report".
  29.   Paradox does only "one-pass" reporting, formatting output and
  30.   printing records as it goes.
  31.  
  32.   There are a number of alternative methods to calculate the
  33.   percent of the total of either a record value or group summary
  34.   value.  We will cover two different methods here.  Both methods
  35.   are available in Paradox 3.5.  However only the query method is
  36.   available in Paradox 3.0x.  The first method is based on a
  37.   calculation held in a new field in the table.  The second is
  38.   based on PAL report features added in Paradox 3.5.
  39.  
  40.   For both of these methods lets assume the following table
  41.   structure:
  42.  
  43.             Table Name: TablName
  44.             Field 1 A10*
  45.             Field 2 A10
  46.             Field 3 D
  47.             Field 4 $
  48.  
  49.   For this example we want to have the percent of total of each
  50.   record and of each group based on Field 3 (date field).  We will
  51.   use Report R1 for this table.
  52.  
  53.   The basic structure of the report is:
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Paradox                                NUMBER  :  789
  75.   VERSION  :  3.0 & up
  76.        OS  :  DOS
  77.      DATE  :  August 26, 1991                          PAGE  :  2/4
  78.  
  79.     TITLE  :  Calculating Percent of Total in a Report
  80.  
  81.  
  82.  
  83.  
  84.   ── page ─────────────────────────────────────────────────────────
  85.   ─── group Field 3 range=month ───────────────────────────────────
  86.   ──── table ──────────────────────────────────────────────────────
  87.    Field 1     Field 2     Field 3   Field 4       Pct. of Total
  88.    ----------  ----------  --------  ------------  -------------
  89.    AAAAAAAAAA  AAAAAAAAAA  mm/dd/yy  (999,999.99)      (999.99)%
  90.   ──── table ──────────────────────────────────────────────────────
  91.                                      -----------       ---------
  92.                     total for month: (999,999.99)      (999.99)%
  93.  
  94.   ─── group Field 3 range=month ───────────────────────────────────
  95.   ── page ─────────────────────────────────────────────────────────
  96.                   Overall total: (999,999,999.99)
  97.   ═════════════════════════════════════════════════════════════════
  98.  
  99.   First Method
  100.   ----- ------
  101.   The first method requires an additional field in the table.
  102.   Therefore the structure will now be:
  103.  
  104.   Table Name: TablName
  105.             Field 1 A10*
  106.             Field 2 A10
  107.             Field 3 D
  108.             Field 4 $
  109.             Total   N
  110.  
  111.   The percentage fields in the report will both be calculated
  112.   fields.  The first calculated field in the Table band will be:
  113.   [Field 4]/[Total]*100.
  114.  
  115.   The calculation in the group footer band will be:
  116.   SUM([Field 4], Group)/[Total]*100
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Paradox                                NUMBER  :  789
  141.   VERSION  :  3.0 & up
  142.        OS  :  DOS
  143.      DATE  :  August 26, 1991                          PAGE  :  3/4
  144.  
  145.     TITLE  :  Calculating Percent of Total in a Report
  146.  
  147.  
  148.  
  149.  
  150.   We will use a query to calculate the total.  The first query for
  151.   this table will be:
  152.  
  153.   QUERY
  154.  
  155.   TablName | Field 4  |
  156.            | Calc Sum |
  157.  
  158.   ENDQUERY
  159.  
  160.   The above query will produce a one field one record answer table.
  161.   We will use a second query (which uses two tables in one query)
  162.   to place the result of the answer table into the report table:
  163.  
  164.   QUERY
  165.  
  166.    Tablname |   Total     |
  167.             | changeto _a |
  168.  
  169.    Answer | Sum of Field 4 |
  170.           | _a             |
  171.  
  172.   ENDQUERY
  173.  
  174.   This will provide us with the necessary data in the table and
  175.   allow the report to take place.  For a variation on this method,
  176.   see Technical Information Bulletin #539.  It has information on
  177.   how to place variables in a report with a lookup table.
  178.  
  179.   Second Method
  180.   ------ ------
  181.  
  182.   The second method is only available in Paradox 3.5.  It uses a
  183.   PAL variable in the report specification.  It also does not
  184.   require an additional field in the table.  You must define the
  185.   variable before the report is printed.  The following script will
  186.   calculate the total and place it into the variable 'Totl'.
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Paradox                                NUMBER  :  789
  207.   VERSION  :  3.0 & up
  208.        OS  :  DOS
  209.      DATE  :  August 26, 1991                          PAGE  :  4/4
  210.  
  211.     TITLE  :  Calculating Percent of Total in a Report
  212.  
  213.  
  214.  
  215.  
  216.   ;SCRIPT BEGINS
  217.  
  218.   CLEAR
  219.   CLEARALL
  220.   Totl=CSUM("TablName", "Field 4") ; Calculates sum of Field 4
  221.   REPORT "TablName" "1"    ; Prints report 1 for TablName
  222.  
  223.   ;SCRIPT ENDS
  224.  
  225.   The calculated fields will be held as Alphanumeric fields.  We
  226.   will use Report  R1 for this table.  The basic structure of the
  227.   report is:
  228.  
  229.   ── page ─────────────────────────────────────────────────────────
  230.   ─── group Field 3 range=month ───────────────────────────────────
  231.   ──── table ──────────────────────────────────────────────────────
  232.    Field 1     Field 2     Field 3   Field 4       Pct. of Total
  233.    ----------  ----------  --------  ------------  -------------
  234.    AAAAAAAAAA  AAAAAAAAAA  mm/dd/yy  (999,999.99)    AAAAAAAAA%
  235.   ──── table ──────────────────────────────────────────────────────
  236.                                      ------------    ----------
  237.                     total for month: (999,999.99)    AAAAAAAAA%
  238.  
  239.   ─── group Field 3 range=month ───────────────────────────────────
  240.   ── page ─────────────────────────────────────────────────────────
  241.                   Overall total: (999,999,999.99)
  242.   ═════════════════════════════════════════════════════════════════
  243.  
  244.   The percentage fields in the report will both be calculated
  245.   fields.  The first calculated field will be in the Table band.
  246.   The calculation will be: [Field 4]/Totl * 100
  247.  
  248.   The calculation in the group footer band will be:
  249.   SUM([Field 4], Group)/Totl * 100
  250.  
  251.   These methods will also work for the percent of a total count of
  252.   records.
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.