Represents a field in a PivotTable report.
The PivotField object is a member of the PivotFieldCollection collection returned by the PivotTable.Fields property. An individual field can be accessed by its name or index in the collection using the PivotFieldCollection.Item property.
To add a PivotField to a pivot table, add it to one of the following collections representing a specific area of the PivotTable report.
- PivotTable.RowFields collection contains all fields located in the row axis area.
- PivotTable.ColumnFields collection contains all fields located in the column axis area.
- PivotTable.PageFields collection contains all fields located in the report filter area.
- PivotTable.DataFields collection contains all fields located in the data area.
In addition to the fields from the source data, a pivot table can also contain calculated fields, whose values are produced based on custom formulas. To add a calculated field to the PivotTable report, use the PivotCalculatedFieldCollection.Add method of the PivotTable.CalculatedFields collection.
Each non-calculated field is made up of items - unique data entries contained in the field. All field items are stored in the PivotItemCollection collection accessible using the PivotField.Items property. You can sort items within a field (PivotField.SortType, PivotField.SortItems), filter them (PivotField.ShowSingleItem, PivotItem.Visible, PivotTable.Filters), or group them to create new subsets of data (PivotField.GroupItems).
A pivot field may also contain one or more calculated items. To add a calculated item to the PivotTable field, use the PivotCalculatedItemCollection.Add method of the PivotField.CalculatedItems collection.
Other members of the PivotField object allow you to modify the field settings. In particular, you can rename a PivotTable field (PivotField.Name), adjust the field layout (PivotField.Layout), specify one or more functions to calculate subtotals for a field (PivotField.SetSubtotal), or restrict an end-user’s ability to move or remove a PivotTable field (PivotField.Behavior).