excel - How can I provide a calculated value that is based on two other values in an Aspose.Cells PivotTable? -


i adding data fields pivottable so:

int totalqty_column = 4; int totalprice_column = 5; . . . pivottable.addfieldtoarea(aspose.cells.pivot.pivotfieldtype.data, totalqty_column); pivottable.addfieldtoarea(aspose.cells.pivot.pivotfieldtype.data, totalprice_column); 

or, providing more context:

aspose.cells.pivot.pivottablecollection pivottables = pivottablesheet.pivottables; int colcount = columns_in_data_sheet;  string lastcolasstr = reportrunnerconstsandutils.getexcelcolumnname(colcount); int rowcount = sourcedatasheet.cells.rows.count; string sourcedataarg = string.format("sourcedatasheet!a1:{0}{1}", lastcolasstr, rowcount); int index = pivottablesheet.pivottables.add(sourcedataarg, "a7", "pivottablesheet"); aspose.cells.pivot.pivottable pivottable = pivottables[index];  pivottable.addfieldtoarea(aspose.cells.pivot.pivotfieldtype.row, description_column);  pivottable.addfieldtoarea(aspose.cells.pivot.pivotfieldtype.column, monthyr_column);  pivottable.addfieldtoarea(aspose.cells.pivot.pivotfieldtype.data, totalqty_column); pivottable.addfieldtoarea(aspose.cells.pivot.pivotfieldtype.data, totalprice_column); 

i need data field based on values supplied 2 data fields (from source data's totalqty_column , totalprice_column columns), totalprice divided total qty.

is possible? if so, how can this?

i create column source data sheet contain value , reference it, if can avoid doing use of calculation "trickery" preferable.

i solved adding column source data sheet, populating making calculation described above (totalprice / totalqty):

decimal avgprice = 0.0m; if ((totalprice > 0.0m) && (quantity > 0)) {     avgprice = totalprice/quantity; } cell = sourcedatasheet.cells[_lastrowaddedpivottabledata, 10]; cell.putvalue(math.round(avgprice, 2)); 

...and referencing new data source column accordingly:

pivottable.addfieldtoarea(aspose.cells.pivot.pivotfieldtype.data, avgprice_column); 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -