I am using C# winforms to create an application that needs to turn a datatable into a pivot table. I have the pivot table working fine from a SQL end, but creating it from a da
Pivot table like that can be easily calculated with free NReco.PivotData aggregation library:
DataTable t; // assume it has: StartDateTime, Data, Tap
var pivotData = new PivotData(
new string[] {"StartDateTime","Tap"},
new AverageAggregatorFactory("Data"),
new DataTableReader(t) );
var pvtTbl = new PivotTable(
new [] {"StartDateTime"}, // row dimension(s)
new [] {"Tap"}, // column dimension(s),
pivotData);
Row and column keys are represented by pvtTbl.RowKeys and pvtTbl.ColumnKeys collections; values / totals could be accessed by indexer (for example: pvtTbl[0,0].Value
) or by row+column key (for example: pivotData[new Key(new DateTime(2012, 3, 30, 11, 42, 00)), new Key(4)].Value
).