You can achieve what you want in the following way:
- configure base
PivotTable
class to order axis with dates in reverse order (descending)
- apply TopPivotTable wrapper to select only first 3 dates (= so they will be actually last 3 days)
- reverse axis keys with
Array.Reverse
. For example, if dates are columns: Array.Reverse(topPvtTbl.ColumnKeys);
-- update --
This approach will not work if underlying table-related calculation relies on the concrete axis order (like RunningValuePivotTable). Alternatively, you can implement your own IPivotTable
wrapper that takes last N items. For example:
public class LastNColumnsPivotTable : IPivotTable {
IPivotTable basePvtTbl;
public LastNColumnsPivotTable(IPivotTable pvtTbl, int lastN) {
basePvtTbl = pvtTbl;
if (basePvtTbl.ColumnKeys.Length>lastN) {
lastColumnKeys = basePvtTbl.ColumnKeys.Skip(basePvtTbl.ColumnKeys.Length - lastN).ToArray();
} else {
lastColumnKeys = basePvtTbl.ColumnKeys;
}
}
public string[] Columns { get { return basePvtTbl.Columns; } }
public string[] Rows { get { return basePvtTbl.Rows; } }
ValueKey[] lastColumnKeys;
public ValueKey[] ColumnKeys { get { return lastColumnKeys; } }
public ValueKey[] RowKeys { get { return basePvtTbl.RowKeys; } }
public IPivotData PivotData { get { return basePvtTbl.PivotData; } }
public IAggregator GetValue(ValueKey rowKey, ValueKey colKey) {
return basePvtTbl.GetValue(rowKey, colKey);
}
}