<tcol>

<tcol> defines a result column in a tabulation or cross-tabulation (e.g., average price).

Description

<tcol> defines the nature of an aggregation in a tabulation. While the <tabu> element identifies the break (grouping) column(s), the <tcol> element defines what column(s) to summarize and the type of summarization to perform. <tcol> must be contained within a <tabu> element.

A tabulation can have any number of <tcol> elements. As of version 10.17, it is no longer necessary (though it is typically desirable) for every <tcol> in a regular tabulation to be unique.

As of version 10.17, cross tabulations can contain multiple <tcol> elements, allowing for multi-metric cross tabulations. The columns specified by the multiple <tcol> elements are grouped together under each column break, and the row-total columns appear at the beginning in <tcol> order. Labels are not provided to differentiate the multiple <tcol> columns unless the attribute cmlabel is specified, in which case the text supplied as the value of cmlabel indicates the row of the cross-tab header on which the <tcol> labels are shown. The attribute cmorder determines whether the <tcol> labels appear in the first or last row of the header and the manner in which the <tcol> columns and column breaks are grouped in the cross tabulation.
Note: Prior to version 10.17, cross tabulations could have only one <tcol> element.

Syntax

<tabu label="[TABULATION_TITLE]" 
    breaks="[GROUPING_COLUMN]">
      <tcol source="[AGGREGATION_COLUMN]" 
      fun="[FUNCTION]"
      label="[COLUMN_HEADING]" 
      format="[FORMAT_VAR]"/>
</tabu>

Attributes

name
The name of the result column.

If not specified, the result column is named ti, where i is an integer number assigned by the system (e.g., t0).

As of version 18.22, name can be used in both simple and multi- <tcol> cross-tabulations. If name is specified, it must be specified and unique for each of the <tcol>s.

source
The name of the column to summarize.

You can use an expression in the source attribute.

weight
For weighted aggregations, the name of the column with which to weight the values in source; or, for functions requiring a second column (e.g., correlation, covariance, dot product), the name of the second column.

For a list of which functions require a second column, see the fun article.

label
Specifies a descriptive column label that may be displayed in the column header at the top of the result column in the grid.

If not specified, the name of the result column is used as the column label.

fun
The fun attribute contains the function that is performed on the column(s) to be aggregated to produce the results column.

For a complete list of available values for this attribute (as well as the functionality each provides), see Functions in <tcol>.

format
The format for the column (see Display formats). 

The default is determined by the type of column.

select
Specifies the selection column for filtering the data to be tabulated. The selection column can have only two possible values: 1 (select) and 0 (do not select).

(Available as of version 13.31)

cmlabel
Specifies the text used to designate the row in the header that displays the <tcol> labels in a multi-column cross tabulation (The attribute cmlabel can be set to an empty string if no designation is needed in the header but the <tcol> labels are still desired.)
Note: If a label is specified for a <tcol>, that label is used in the header for that <tcol>; otherwise, the default label for the <tcol> is used.

By default, the row of labels appears in the final row of the cross-tab header. As of version 10.19, you can specify whether it appears in the first row or the last row of the header using the cmorder attribute, which also determines the grouping of the <tcol> columns and column breaks.

(Available as of version 10.17)

cmorder
Specifies where to place the <tcol> labels in a multi-column cross tabulation and how to group <tcol> columns and column breaks
Note: The attribute cmlabel must be specified; otherwise, the <tcol> labels are not shown at all.
first
Places the <tcol> labels in the top row of the header before the column breaks; groups columns first by which <tcol> they came from, then by column breaks.
last
Places the <tcol> labels in the last row of the header after the column breaks; groups columns first by column breaks, then by which <tcol> they came from.

The default is last.

(Available as of version 10.19)

cname
Adds a prefix [PREFIX] to the name value. As with name, if cname is specified, it must be specified and unique for each of the <tcol>s.

In a single <tcol>, cross-tabulation, [PREFIX] is used instead of m. For example, if you have <tcol cname="foo">, the column break columns will be foo0, foo1, foo2, etc. (one for each column break).

In a multi-<tcol> cross-tabulation, [PREFIX]i is used instead of mi_. (i is an integer assigned by the system.) For example, if you have <tcol cname="foo"...><tcol cname="bar"...>, the column break columns will be foo0, bar0, foo1, bar1, foo2, bar2, etc.
Note: If <tabu cmorder="first">, the multi- <tcol> cross-tabulation is in the following order: foo0, foo1, foo2,...bar0, bar1, bar2...

(Available as of version 18.22)

clabel
Adds a prefix to the labels of the column break columns for that <tcol>. The prefix is appended with a space, unless the prefix ends with a newline (the ` character).

(Available as of version 18.22)

Example

In this example, the base table is pub.demo.retail.item.

<base table="pub.demo.retail.item"/>
<tabu label="Tabulation on Sales Item Detail" breaks="store">
    <tcol source="sales" fun="sum" label="Sum of`Sales"/>
</tabu>
Note: The grouping (breaks) column(s) in the tabulation is specified in the <tabu> element. See <tabu> for details.

Example: Multi-metric cross tabulation

As of version 10.17, cross tabulations can contain multiple <tcol> elements, allowing for multi-metric cross tabulations.

This example shows a multi-metric cross tabulation that aggregates both the sum of extended sales and the average cost broken out by transaction date for every store in the table pub.doc.retail.salesdetail. The resultant table contains one row for every store (as specified by the breaks attribute). The first column in the table contains the stores, the second displays the row totals related to the sum of extended sales, the third shows the row totals for the average cost, and the remaining columns show the total sales and average cost for each date (as specified by the cbreaks attribute). The <tcol> labels appear in the last row in the header (as specified by the cmorder attribute), and that row is labeled with the text Summarization (as specified by the cmlabel attribute). Note that the header uses the label specified with the <tcol> associated with the sum of sales (Sum of Sales) whereas a default label is used for the average cost (Avg Cost) since no label was specified for that <tcol>.

<base table="pub.doc.retail.salesdetail"/>
<tabu label="Sales by Store" breaks="store" 
 cbreaks="trans_date" cmlabel="Summarization" cmorder="last">
  <break col="store" sort="up"/>
  <tcol fun="sum" source="xsales" 
   label="Sum of Sales" format="type:currency"/>
  <tcol fun="avg" source="cost" format="type:currency"/>
</tabu>

When applied to the table the results appear as follows: