Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pivot Sort #1307

Closed
dfinke opened this issue Nov 13, 2022 Discussed in #1306 · 1 comment
Closed

Pivot Sort #1307

dfinke opened this issue Nov 13, 2022 Discussed in #1306 · 1 comment

Comments

@dfinke
Copy link
Owner

dfinke commented Nov 13, 2022

Discussed in #1306

Originally posted by RoYoMi November 12, 2022
I have created a pivot table but it don't see a way to make it sort the output by the Grand Total field.

In Excel I can manually right click the a total field and choose sort.

Here is my setup:

 $Excel = $Output.RawData `
       | Select-Object @{n="Date"; e={$_.Date | Get-Date}}, @{n="DateYM"; e={$_.Date | Get-Date -Format "yyyy`nMMM"}}, ComputerName, DisplayName, Commandlet, ModuleVersion, Event, FullCommand `
       | Export-Excel $ExcelFile @ExportExcelOptions -Passthru

    $PivotTableOptions = @{
        ExcelPackage        = $Excel
        PivotTableName      = "ByCommand"
        SourceWorkSheet     = $Excel.Sheet1
        PivotRows           = "Commandlet"
        PivotData           = @{"Commandlet" = "Count"}
        PivotColumns        = @("DateYM")
        PivotTotals         = "Both"
        PivotTableStyle     = "Light16"
        }
    $pt = Add-PivotTable @PivotTableOptions -PassThru

That code creates this:

image

I found this teaser in v5.3 where it talks about sort on pivot tables, but I can't figure it out.

Did I miss something in the docs?
Or is this even possible?

@dfinke dfinke self-assigned this Nov 13, 2022
@stale
Copy link

stale bot commented Dec 24, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Dec 24, 2022
@stale stale bot closed this as completed Dec 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant