Show pivot table values as percentages PivotData C# examples
This documentation describes usage of
PercentagePivotTable
(Toolkit component).
Let's assume that you already have IPivotTable
instance with some values and need to display these values as percentage.
It is possible to get desired result by wrapping original pivot table model with PercentagePivotTable
wrapper:
var basePvtTbl = new PivotTable( new[]{"product"}, new[]{"country"}, pvtData); var percentPvtTbl = new PercentagePivotTable( basePvtTbl, PercentagePivotTable.PercentageMode.GrandTotal); percentPvtTbl.RoundDigits = 0;
It is possible to calculate a percentage of parent row total or parent column total; the following percentage calculation types are available:
PercentagePivotTable.PercentageMode.GrandTotal
PercentagePivotTable.PercentageMode.RowTotal
PercentagePivotTable.PercentageMode.ColumnTotal
If pivot table has several measures it is possible to specify which measure should be calculated as the percentage with
PercentagePivotTable
constructor that accepts measure index as a 3rd parameter:
var percentPvtTbl = new PercentagePivotTable( basePvtTbl, PercentagePivotTable.PercentageMode.GrandTotal, 0);
Note: you can apply
PercentagePivotTable
several times to calculate percentage for specific measures.Germany | Belgium | Totals | |
---|---|---|---|
Product1 | 15 | 17 | 32 |
Product2 | 10 | 1 | 11 |
Totals | 25 | 18 | 43 |
Germany | Belgium | Totals | |
---|---|---|---|
Product1 | 34% | 40% | 74% |
Product2 | 23% | 3% | 26% |
Totals | 58% | 42% | 100% |