ImportExcel icon indicating copy to clipboard operation
ImportExcel copied to clipboard

PivotTable Options Display as classic PivotTable Layout and Field Settings as Repeat item labels

Open blhf opened this issue 7 years ago • 6 comments

I have to create a workbook with 2 sheets. 1 for raw and the other 1 for summary. Basically the data I have is:

image

This data came from SQL and I was able to export it to excel.

But my second challenge is how to create a summary in another worksheet. something like this:

image

Main objective is to tweak the Pivot table option like this.

image

Then remove the totals per row. To have the same output as the fig 2. But can we do it as automated as I will do the automated email sending after this.

blhf avatar Jul 31 '19 14:07 blhf

Not sure I know how to get a pivot table in that shape. Pivot tables are hierarchical.

image

dfinke avatar Jul 31 '19 16:07 dfinke

sample.xlsx

Hi @dfinke . I attached the workbook.

blhf avatar Jul 31 '19 16:07 blhf

Thanks for the workbook. This is a new one on me. Don't know how to manually shape the pivot table the way you did. Here's mine.

@jhoneill Do you know how to shape the pivot table that way?

pivot.xlsx

dfinke avatar Jul 31 '19 18:07 dfinke

image I can get roughly the same like this

$excel = $data | export-excel -path $env:temp\temp.xlsx -PassThru                                                                                                                                                        
$pivot  = Add-PivotTable -PivotTableName foo -ExcelPackage $excel -SourceWorkSheet sheet1 -PivotRows "Company Name", "CompanyID", "Country" -PivotData @{sales="Sum"} -NoTotalsInPivot  -PassThru                        
 $pivot.RowFields[0].SubTotalFunctions="None"                                                                                                                                                                             
 $pivot.RowFields[1].SubTotalFunctions="None"                                                                                                                                                                             
 $pivot.RowFields[2].SubTotalFunctions="None"                                                                                                                                                                             
 $pivot.RowFields[0].Compact = $false                                                                                                                                                                                     
 $pivot.RowFields[1].Compact = $false                                                                                                                                                                                     
 $pivot.RowFields[2].Compact = $false                                                                                                                                                                                     
 $pivot.RowFields[0].Outline = $false                                                                                                                                                                                     
 $pivot.RowFields[1].Outline = $false                                                                                                                                                                                     
 $pivot.RowFields[2].Outline = $false                                                                                                                                                                                     
 $pivot.EnableDrill = $false                                                                                                                                                                                              
 $pivot.ShowDrill = $false                                                                                                                                                                                                


I have to manually turn on "repeat label items" because that is not settable by EPPLus, and I can't set the column headings to be other than row labels and total

jhoneill avatar Jul 31 '19 23:07 jhoneill

Thanks @jhoneill, need to explore field settings. Too bad EPPlus doesn't support it.

dfinke avatar Aug 01 '19 01:08 dfinke

@dfinke I found a work around for this. I used t-sql to do the data pivot for me. However if you find this issue worth looking into I'll be glad if I can be of any assistance.

Thank you for this wonderful PS module. More power to you!

blhf avatar Aug 02 '19 09:08 blhf