Show pivot table values as running total PivotData C# examples


This documentation describes usage of RunningValuePivotTable (Toolkit component).

Let's assume that you already have IPivotTable instance with some values and need to display these values as running total. It is possible to get desired result by wrapping original pivot table model with RunningValuePivotTable:

var basePvtTbl = new PivotTable(
  new[]{"product"}, new[]{"quarter"}, pvtData);
var runningTotalPvtTbl = new RunningValuePivotTable(
  basePvtTbl, 
  RunningValuePivotTable.Direction.Row);

Running value can can be calculated from top to down (Direction.Column) or from left to right (Direction.Row).

If pivot table has several measures it is possible to specify which measure should be calculated as the running value with constructor that accepts measure index as a 3rd parameter:

var percentPvtTbl = new RunningValuePivotTable(
  basePvtTbl, 
  PercentagePivotTable.PercentageMode.Row, 1);
Note: you can apply RunningValuePivotTable several times to calculate running values for specific measures.
  Q1 Q2 Q3 Q4 Totals
Product1 2 4 3 5 14
Product2 1 1 1 1 4
Totals 3 5 4 6 18
  Q1 Q2 Q3 Q4 Totals
Product1 2 6 9 14
Product2 1 2 3 4
Totals 3 8 12 18

By default RunningValuePivotTable uses SUM function to calculate a running value; it is possible to change aggregate function in the following way:

runningTotalPvtTbl.UseAggregateFunction( new AverageAggregatorFactory(null) );

As result running average will be calculated instead of running total.