addtotals
addtotals [options(...)]?, [column: storable]*
Adds a column that totals the numeric columns in each row.
addtotals compiles only when the enable_opal_totals feature flag is on for the customer. The same flag gates addcoltotals.
By default the new column is named Total and sums every int64, float64, and numeric column. options(fieldname: "name") chooses a different name. Timestamp, duration, string, bool, and object columns are left out of that default sum, including the valid-from and valid-to columns. A null cell counts as zero. The destination cannot be the valid-from, valid-to, or a primary key column. Any other existing column with the destination name is overwritten, and that column is left out of the default sum and out of quoted patterns so its previous value is not added into itself. Name that column in the argument list to include the previous value.
Pass column names or quoted patterns ("amount*", "*size*") to choose the columns. A pattern uses * and ?; every other character, including / and [, is matched literally. Patterns and the default column set skip hidden and internal columns. A pattern that matches nothing is an error. A duration column is included when it is named or matched by a pattern, and a row total of only duration columns has type duration. A timestamp column cannot be totaled. Mixing a duration column with an int or float column is an error.
options(col: true) also appends one summary row, as addcoltotals does, including options(labelfield: column, label: "Total"). options(row: false) turns the new column off. Setting both row and col to false is an error.
Total on the summary row
With options(col: true), each data row still gets a Total, and a summary row is appended. Total still sums only int64, float64, and numeric columns. The summary row sums those columns and also sums each duration column.
The Total value on the summary row is the column total of the Total column: the sum of the per-row Total values. It is not a row total of the summary row. A duration total therefore appears in its own column on the summary row and is not added into Total.
For columns count (int64) and latency (duration), Total on each data row equals count. On the summary row, count is the sum of count, latency is the sum of latency, and Total is the sum of the data rows' Total values.
The summary row is sorted last. 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. Column totals read every input row that reaches the verb.
Options
| Option | Type | Meaning |
|---|---|---|
| fieldname | string | Name of the row-total column. Defaults to Total. |
| row | bool | When true, add the row-total column. Defaults to true. |
| col | bool | When true, append a summary row of column totals. Defaults to false. |
| labelfield | string | Column that receives the summary label. Used when col is true. |
| label | string | Text written into labelfield on the summary row. Defaults to Total. |
Categories
Accelerable
addtotals is sometimes accelerable, depending on options used. A dataset that only uses accelerable verbs can be accelerated, making
queries on the dataset respond faster.
Examples
addtotals options(fieldname: "Total"), "price"
Adds a row total of the price column on the inventory dataset.
Updated 7 minutes ago