Cmdlet
Add-OfficeExcelPivotTable
Adds a pivot table to a worksheet.
Syntax
Add-OfficeExcelPivotTable
-Address <String>
[-ColumnField <String[]>]
[-ColumnHeaderCaption <String>]
[-CustomListSort]
[-DataDisplayName <String[]>]
[-DataField <String[]>]
[-DataFunction <ExcelPivotDataFunction[]>]
[-DataNumberFormat <String[]>]
[-DataOnRows]
[-Document <ExcelDocument>]
[-EnableDrill]
[-ErrorCaption <String>]
[-FieldCompact <String[]>]
[-FieldHiddenItems <Hashtable>]
[-FieldHideDropDowns <String[]>]
[-FieldInsertBlankRow <String[]>]
[-FieldInsertPageBreak <String[]>]
[-FieldListSort <Ascending| Descending>]
[-FieldNoDefaultSubtotal <String[]>]
[-FieldOutline <String[]>]
[-FieldSort <Hashtable>]
[-FieldSubtotalTop <String[]>]
[-FieldVisibleItems <Hashtable>]
[-GrandTotalCaption <String>]
[-Layout <Compact| Outline| Tabular>]
[-MissingCaption <String>]
[-Name <String>]
[-NoColumnGrandTotals]
[-NoRowGrandTotals]
[-PageField <String[]>]
[-PageFieldSelection <Hashtable>]
[-PassThru]
[-PreserveFormatting]
-Range <String>
[-RefreshOnOpen]
[-RowField <String[]>]
[-RowHeaderCaption <String>]
[-SaveSourceData]
[-Sheet <OfficeSheetSelector>]
[-ShowDataDropDown]
[-ShowDataTips]
[-ShowDrill]
[-ShowDropZones]
[-ShowEmptyColumns]
[-ShowEmptyRows]
[-ShowHeaders]
[-ShowMemberPropertyTips]
[-SourceSheet <OfficeSheetSelector>]
[-Style <String>]
[<CommonParameters>]#Parameter set:
RangeAdd-OfficeExcelPivotTable
-Address <String>
[-ColumnField <String[]>]
[-ColumnHeaderCaption <String>]
[-CustomListSort]
[-DataDisplayName <String[]>]
[-DataField <String[]>]
[-DataFunction <ExcelPivotDataFunction[]>]
[-DataNumberFormat <String[]>]
[-DataOnRows]
[-Document <ExcelDocument>]
[-EnableDrill]
[-ErrorCaption <String>]
[-FieldCompact <String[]>]
[-FieldHiddenItems <Hashtable>]
[-FieldHideDropDowns <String[]>]
[-FieldInsertBlankRow <String[]>]
[-FieldInsertPageBreak <String[]>]
[-FieldListSort <Ascending| Descending>]
[-FieldNoDefaultSubtotal <String[]>]
[-FieldOutline <String[]>]
[-FieldSort <Hashtable>]
[-FieldSubtotalTop <String[]>]
[-FieldVisibleItems <Hashtable>]
[-GrandTotalCaption <String>]
[-Layout <Compact| Outline| Tabular>]
[-MissingCaption <String>]
[-Name <String>]
[-NoColumnGrandTotals]
[-NoRowGrandTotals]
[-PageField <String[]>]
[-PageFieldSelection <Hashtable>]
[-PassThru]
[-PreserveFormatting]
[-RefreshOnOpen]
[-RowField <String[]>]
[-RowHeaderCaption <String>]
[-SaveSourceData]
[-Sheet <OfficeSheetSelector>]
[-ShowDataDropDown]
[-ShowDataTips]
[-ShowDrill]
[-ShowDropZones]
[-ShowEmptyColumns]
[-ShowEmptyRows]
[-ShowHeaders]
[-ShowMemberPropertyTips]
-SourceSheet <OfficeSheetSelector>
[-Style <String>]
[<CommonParameters>]#Parameter set:
SourceSheetAdd-OfficeExcelPivotTable
-Address <String>
[-ColumnField <String[]>]
[-ColumnHeaderCaption <String>]
[-CustomListSort]
[-DataDisplayName <String[]>]
[-DataField <String[]>]
[-DataFunction <ExcelPivotDataFunction[]>]
[-DataNumberFormat <String[]>]
[-DataOnRows]
[-Document <ExcelDocument>]
[-EnableDrill]
[-ErrorCaption <String>]
[-FieldCompact <String[]>]
[-FieldHiddenItems <Hashtable>]
[-FieldHideDropDowns <String[]>]
[-FieldInsertBlankRow <String[]>]
[-FieldInsertPageBreak <String[]>]
[-FieldListSort <Ascending| Descending>]
[-FieldNoDefaultSubtotal <String[]>]
[-FieldOutline <String[]>]
[-FieldSort <Hashtable>]
[-FieldSubtotalTop <String[]>]
[-FieldVisibleItems <Hashtable>]
[-GrandTotalCaption <String>]
[-Layout <Compact| Outline| Tabular>]
[-MissingCaption <String>]
[-Name <String>]
[-NoColumnGrandTotals]
[-NoRowGrandTotals]
[-PageField <String[]>]
[-PageFieldSelection <Hashtable>]
[-PassThru]
[-PreserveFormatting]
[-RefreshOnOpen]
[-RowField <String[]>]
[-RowHeaderCaption <String>]
[-SaveSourceData]
[-Sheet <OfficeSheetSelector>]
[-ShowDataDropDown]
[-ShowDataTips]
[-ShowDrill]
[-ShowDropZones]
[-ShowEmptyColumns]
[-ShowEmptyRows]
[-ShowHeaders]
[-ShowMemberPropertyTips]
[-Style <String>]
-Table <String>
[<CommonParameters>]#Parameter set:
TableExamples
Summarise sales in a pivot table
Open-OfficeExcel -Path .\Reports\Q3-Sales.xlsx {
ExcelSheet 'Orders' {
ExcelPivotTable -Range A1:F500 -Address H2 -RowField Region -DataField Amount -DataFunction Sum
}
}Builds a pivot table of revenue by region from the order data in A1:F500.
Pivot revenue by region and quarter
$orders = Import-OfficeCsv -Path .\Data\Orders-2026.csv
New-OfficeExcel -Path .\Reports\Sales-2026.xlsx {
ExcelSheet 'Orders' {
ExcelTable $orders -Name Orders
ExcelPivotTable -Table Orders -Address J3 -Name SalesPivot -RowField Region -ColumnField Quarter -PageField Product -DataField Amount -DataFunction Sum -DataDisplayName 'Revenue' -DataNumberFormat '#,##0' -Layout Tabular -RefreshOnOpen
}
}Writes a year of orders and pivots them by region and quarter with a product filter, naming the pivot so a slicer and conditional formats can refer to it.
Put the pivot on its own sheet
Open-OfficeExcel -Path .\Reports\Q3-Sales.xlsx {
ExcelSheet 'Summary' {
ExcelPivotTable -SourceSheet Orders -Address A3 -RowField Region -ColumnField Product -DataField Amount -DataFunction Sum
}
}Builds a summary sheet whose pivot reads all the data on the Orders sheet.
Parameters
- -Address String
- A1 address of the target cell.
- -ColumnField String[]
- Column fields (header names).
- -ColumnHeaderCaption String
- Optional column header caption.
- -CustomListSort SwitchParameter
- Use Excel custom-list sorting.
- -DataDisplayName String[]
- Display names for data fields.
- -DataField String[]
- Data fields (header names). Defaults to the last column when omitted.
- -DataFunction ExcelPivotDataFunction[]
- Aggregation functions (Sum, Count, Average, etc.).
- Possible values:
Average,Count,CountNumbers,Maximum,Minimum,Product,StandardDeviation,StandardDeviationP,Sum,Variance,VarianceP - -DataNumberFormat String[]
- Number format codes for data fields.
- -DataOnRows SwitchParameter
- Show data fields on rows.
- -Document ExcelDocument
- Caller-owned workbook; omission uses the enclosing Excel content block.
- -EnableDrill SwitchParameter
- Allow users to drill into pivot details in Excel.
- -ErrorCaption String
- Optional error-value caption.
- -FieldCompact String[]
- Fields using compact field layout.
- Field item captions to hide, for example @{ Region = @('Legacy') }.
- -FieldHideDropDowns String[]
- Fields whose filter drop-downs should be hidden.
- -FieldInsertBlankRow String[]
- Fields that insert blank rows after items.
- -FieldInsertPageBreak String[]
- Fields that insert page breaks after items.
- -FieldListSort ListSortDirection
- Controls the ordering of the pivot field list.
- Possible values:
Ascending,Descending - -FieldNoDefaultSubtotal String[]
- Fields with default subtotal disabled.
- -FieldOutline String[]
- Fields using outline field layout.
- -FieldSort Hashtable
- Field sort map, for example @{ Region = 'Ascending' }.
- -FieldSubtotalTop String[]
- Fields with subtotals shown at the top.
- -FieldVisibleItems Hashtable
- Field item captions to keep visible, hiding other known items.
- -GrandTotalCaption String
- Optional grand total caption.
- -Layout ExcelPivotLayout
- Pivot layout (Compact, Outline, Tabular).
- Possible values:
Compact,Outline,Tabular - -MissingCaption String
- Optional missing-value caption.
- -Name String
- Optional pivot table name.
- -NoColumnGrandTotals SwitchParameter
- Disable column grand totals.
- -NoRowGrandTotals SwitchParameter
- Disable row grand totals.
- -PageField String[]
- Page fields (header names) used as filters.
- -PageFieldSelection Hashtable
- Selected page-field item captions, for example @{ Product = 'Standard' }.
- -PassThru SwitchParameter
- Emits the native result after the operation.
- -PreserveFormatting SwitchParameter
- Preserve pivot formatting when Excel refreshes the pivot table.
- -Range String
- A1 cell range on the selected worksheet.
- -RefreshOnOpen SwitchParameter
- Refresh the pivot cache when the workbook opens.
- -RowField String[]
- Row fields (header names).
- -RowHeaderCaption String
- Optional row header caption.
- -SaveSourceData SwitchParameter
- Save pivot source cache records in the workbook package.
- -Sheet OfficeSheetSelector
- Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.
- -ShowDataDropDown SwitchParameter
- Show the data drop-down.
- -ShowDataTips SwitchParameter
- Show pivot data tips.
- -ShowDrill SwitchParameter
- Show drill indicators.
- -ShowDropZones SwitchParameter
- Show pivot drop zones.
- -ShowEmptyColumns SwitchParameter
- Show empty columns.
- -ShowEmptyRows SwitchParameter
- Show empty rows.
- -ShowHeaders SwitchParameter
- Show field headers.
- -ShowMemberPropertyTips SwitchParameter
- Show member property tips.
- -SourceSheet OfficeSheetSelector
- Gets or sets the source worksheet name, one-based position or native worksheet.
- -Style String
- Built-in chart style identifier.
- -Table String
- Native Excel table used to resolve the source range or header.
Common Parameters
This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters.