addcoltotals

addcoltotals [options(...)]?, [column: storable]*

Appends one summary row with a total of each numeric or duration column.

addcoltotals compiles only when the enable_opal_totals feature flag is on for the customer. The same flag gates addtotals.

With no column arguments, every int64, float64, numeric, and duration column is summed. Timestamp, string, bool, and object columns are left out, including valid-from and valid-to. Pass column names or quoted patterns ("count*", "*bytes*") to choose the columns. A timestamp column cannot be totaled. Nulls are skipped, matching SQL sum. If no int64, float64, numeric, or duration column is present, the summary row is still appended.

addtotals with options(col: true) uses this summary row and also adds a Total column. That column does not include duration values. The Total value on the summary row is the column total of Total, not a row total of the summary row.

The input may be a Table, Event, Interval, or Resource. The output is a Table: time columns remain, with a null time on the summary row, and primary keys are cleared. A time-series chart no longer applies, and a later timechart rejects the result. statsby, sort, filter, and make_col still accept it.

options(labelfield: column, label: "Total") writes the label on the summary row when that column is a string, an existing variant, or a name that does not exist yet. A missing column is created as a string: null on the data rows and the label on the summary row. An existing variant stays variant. Any other existing type is left unchanged, so the summary cell keeps its sum or stays null. The default label is Total. label without labelfield has no effect.

The summary row is sorted last using a hidden column. A later sort or pick_col keeps it last. A later limit, or the row limit applied when results are displayed, can drop it when there are more data rows than the limit. The totals cover every row that reaches the verb.

Options

OptionTypeMeaning
labelfieldstringColumn that receives the summary label on the summary row.
labelstringText written into labelfield on the summary row. Defaults to Total.

Categories

Accelerable

addcoltotals is never accelerable. A dataset that only uses accelerable verbs can be accelerated, making
queries on the dataset respond faster.

Examples

addcoltotals options(labelfield: "title", label: "Grand Total"), "price"

Appends a summary row that totals the named price column and writes a custom label into title.

addcoltotals

With no column list, the summary row totals every int64, float64, numeric, and duration column.

addcoltotals "p*"

A quoted pattern selects which columns to total. "p*" matches names that start with p.

addcoltotals options(labelfield: "summary"), "price"

A labelfield name that is not already a column is created as a string. Data rows get null; the summary row gets the default label Total.

addcoltotals

The default summary includes duration columns as well as numeric columns.

addcoltotals "count"

Nulls are skipped in the column total, matching SQL sum, so a null count does not change the summary value.

addcoltotals "price"
limit 2

A later limit can drop the summary row when there are more data rows than the limit. Here the limit keeps two rows, so the summary row and the third data row are cut. The totals still cover every row that reached addcoltotals.

addcoltotals "price"
sort desc(price)

A later sort reorders the data rows and keeps the summary row last.

addcoltotals "price"

The result is a Table. Time columns remain, with a null time on the summary row, so a later timechart is rejected.


Did this page help you?