table.CROSSTAB Function
Syntax
Arguments
- Crosstab.db
Type "C". The filename of the resulting table.
- Crosstab.filter
Type "CE". Optional. Default = ".T." (all records). A character filter expression that selects the records to process.
- Crosstab.row
Type "C". The field or combination of fields that will occupy the crosstabs horizontal axis.
- Crosstab.column
Type "C". The name of the field or combination of fields that will occupy the crosstabs vertical axis.
- Crosstab.tabulate
Type "C". The name of the field or combination of fields that you want to summarize in the crosstab.
- Crosstab.code
Type "N". The following Summary Operation Codes to specify the type of summarization performed on the tabulation expression.
- Code
- Operation and Description
- SUM_OP_TOTAL (1)
Operation: Total. Returns the sum of values for the specified field or expression.
- SUM_OP_COUNT (2)
Operation: Count. Returns a count of the number of records included in the specified field or expression.
- SUM_OP_MIN (3)
Operation: Min. Returns the minimum (smallest) value for the specified field or expression.
- SUM_OP_MAX (4)
Operation: Max. Returns the maximum (largest) value for the specified field or expression.
- SUM_OP_AVERAGE (5)
Operation: Average. Returns the average of values for the specified field or expression.
- SUM_OP_FIRST (6)
Operation: First. Returns the first value for the specified field or expression.
- SUM_OP_LAST (7)
Operation: Last. Returns the last value for the specified field or expression.
- Crosstab.options
Type "C". Optional. Default = Ascending with duplicate records. Specifies the options used when ordering the Result table records. This string can contain one or more of the following index codes:
- Code
- Description
- D
The Descending Order option puts the records in descending alphabetical order or, for a numeric field, from highest to lowest value.
- U
The Unique option uses only unique records in the crosstab.
Description
Cross tabulate records of database into result database.
Discussion
The <TBL>.CROSSTAB() method is a high-level utility used to cross-tabulate the records of a specified table, creating a new table, specified by the crosstab.db parameter, to store the result. Most parameters passed to <TBL>.CROSSTAB()through the crosstab function variable correspond directly with the prompts appearing on the Create New Operation screen after clicking Operations > New > Crosstab. To define a crosstab, you specify the data you want to summarize and how the rows and columns in the resulting table are to be generated. You can perform cross-tabulation on character, numeric, date, and logical fields. Some summary operations do not make sense with some field types (e.g., totaling date values). The crosstab.row parameter contains the field or combination of fields that will occupy the crosstabs horizontal axis. The crosstab.column is the name of the field or combination of fields that will occupy the crosstabs vertical axis. These expressions pertain to the Group by row and Group by column operators on the Crosstab screen. The crosstab.tabulate parameter is the name of the field or combination of fields that you want to summarize in the crosstab. You use the following Summary Operation Codes to specify the type of summarization performed on the tabulation expression: The crosstab.options parameter allows you to specify the options used when ordering the Result table records.
Example
This script creates a crosstab that shows the number of people with the same last name, for each city and in each state.
dim tbl as P tbl = table.open("c:\a5\a_sports\customer.dbf") crosstab.db = "c:\a5\a_sports\result.dbf" crosstab.filter = "" crosstab.row = "LAST_NAME" crosstab.column = "STATE_PROV" crosstab.options = "I" crosstab.tabulate = "LAST_NAME" crosstab.code = 2 tbl.crosstab() tbl.close()
Alpha Anywhere ignores any query that may have been applied to the table. In the following example, all records are summarized, not just the records in the current query.
dim tbl as P tbl = table.open("c:\a5\a_sports\customer.dbf") query.filter = "state = 'MA' " index = tbl.query_create() crosstab.filter = "" crosstab.row = "LAST_NAME" crosstab.column = "STATE_PROV" crosstab.options = "I" crosstab.tabulate = "LAST_NAME" crosstab.code = 2 tbl.crosstab() tbl.close()
See Also