Pivot table sorting

Hi, is it possible to sort a pivot table PivotField sub total?

var pivotField = myPivotTable.RowFields.Add("MyParts");   
pivotField.Subtotals = PivotFieldSubtotalTypes.Automatic;

Hi Mich,

Yes, you can use PivotField.Sort methods.


Hi Mario,

Thank you for replying.

Here’s the setup for my pivot table, I am trying to sort the pivot table by Sub Totals in descending order.

var brand = myPivotTable.RowFields.Add("Brand");
brand.SubTotals = PivotFieldSubTotalTypes.Automatic;
brand.LayoutForm = PivotFielLayoutForm.Tabular;

var model = myPivotTable.RowFields.Add("Model");
model.LayoutForm = PivotFielLayoutForm.Tabular;

var soldQty = myPivotTable.DataFields.Add("SoldQty");
soldQty.Function = PivotFieldCalculationType.Sum

The PivotField.Sort has two versions. Do you have an example on how I can use the PivotField.Sort() to sort the Sub Totals in descending order?

This is an image of what I have achieved so far and what I want to achieve.

Can you please send us your XSLX file?
I’ll investigate it and let you know how you can do this.