Running total

Commands

dbr.running_total - Calculate running total for a column

Syntax

select 'dbr.running_total', ColumnRef [, SourceColumnRef ]

Explanation

A running total is the sum of any given column that is incremented/decremented row by row.

The command has two options. When only one parameter is given, the running total is calculated over the column given. If the second parameter is given, the column in the first parameter gets the running total of the second column's value. The running total can be used both in tabular reports and in charts.

Examples

Using running total in a tabular report

A 'Running total' is a column that is calculated from the column itself and 'Running total 2' is a column that is calculated from 'Revenue'-column


select 'dbr.running_total', 'Running total';
select 'dbr.running_total', 'Running total 2', 'Revenue';

select 
  revenue_month as 'Month', 
  revenue as 'Revenue', 
  revenue as 'Running total', 
  null as 'Running total 2'
from mydb.data;

Using a running total in a chart

Drawing a cumulative revenue chart


select 'dbr.chart', 'line', 'Cumulative Revenue';
select 'dbr.running_total', 'Revenue';

select 
  revenue_month as 'Month', 
  revenue as 'Revenue'
from mydb.data;