table.FIELD_STATISTICS Function

Syntax

V Field_Statistics(C Expr,P stats)

Arguments

Expr

An expression or value that selects some or all of the fields in the table.

stats

The name of the Statistics dot variable that will receive the answers.

Description

Collects statistics for passed in expression/field.

Discussion

The <TBL>.FIELD_STATISTICS() method computes statistics (first value, last value, minimum value, count, total, average, standard deviation and variance) for Expression, for all of the currently selected records in the table referenced by <TBL>. The statistics are stored in a Statistics dot variable. For example, the command:

tbl.field_statistics("amount_due", answer)

creates dot variables such as: answer.count, answer.total, answer.maximum etc. The following dot variables are created:

Dot Variable
Description
.count

Number of records in current index/query list. Created for All Expression Types.

.minimum

Minimum value in field/expression. Created for All Expression Types.

.maximum

Maximum value in field/expression. Created for All Expression Types.

.first

Value of field/expression in first record in current selection of records. Created for All Expression Types.

.last

Value of field/expression in last record in current selection of records. Created for All Expression Types.

.total

Total of field/expression for all records in current selection of records. Created for Numeric Expression Types.

.average

Average of field/expression for all records in current selection of records. Created for Numeric Expression Types.

.standard

Standard deviation of field/expression for all records in current selection of records. Created for Numeric Expression Types.

.variance

Variance of field/expression for all records in current selection of records. Created for Numeric Expression Types.

Example 

This script is attached to a button on a form. It computes the field statistics for the amount_due field.

dim tbl as P
'initialize the "answer" dot variable
answer.count = 0
tbl = table.current()
tbl.field_statistics("amount_due",answer)
ui_msg_box("Answer","Count: " + answer.count + CRLF()+ "Total: " + answer.total)

If you wanted to compute statistics for just customers in "MA".

dim tbl as P
tbl = table.current()
query.filter = "state = 'ma'"
i = tbl.query_create()
'initialize the "answer" dot variable
answer.count = 0
tbl.field_statistics("amount_due",answer)
ui_msg_box("Answer","Count: " + answer.count + CRLF()+ "Total: " + answer.total)

See Also