将CSV文件数据分组以创建报告

问题描述 投票:1回答:1

我有一个包含以下字段的CSV文件:

Excel Table

Report2

如何使用以下字段创建报告?

$lookupDatafiltered = Import-Csv -Path .\lookups_shutdown.csv

$lookupDatafiltered | Group-Object Region, Country, Status | Select-Object @{n='Region';e={$_.Group[0].Region}}, @{n='Country';e={$_.Group[0].Country}},@{n='Status';e={$_.Group[0].Status}}, Count | Sort-Object -Property Region , Country | export-csv -Path "C:\change\Country.csv" -NoTypeInformation

如何同时获得每个国家/地区导出的CSV的状态计数

powershell object report
1个回答
0
投票

使用给定的代码段作为辅助结果:

$lookupDatafiltered = Import-Csv -Path .\lookups_shutdown.csv
$lookupDataAux = $lookupDatafiltered | | Group-Object Region, Country, Status | 
    Select-Object @{n='Region' ;e={$_.Group[0].Region }}, 
                  @{n='Country';e={$_.Group[0].Country}},
                  @{n='Status' ;e={$_.Group[0].Status }}, 
                  Count | 
      Sort-Object -Property Region, Country, Status
$lookupDataAux  | Group-Object -Property Region,Country | 
    Select-Object @{n='Region' ;e={$_.Group[0].Region }}, 
                  @{n='Country';e={$_.Group[0].Country}},
                  @{n='up'     ;e={[int]($_.Group | ForEach-Object { if( $PSItem.Status -EQ 'up'   ) { $PSItem| Select-Object -ExpandProperty Count }})}},
                  @{n='down'   ;e={[int]($_.Group | ForEach-Object { if( $PSItem.Status -EQ 'down' ) { $PSItem| Select-Object -ExpandProperty Count }})}},
                  @{n='total'  ;e={($_.Group | Measure-Object -Property Count -Sum).Sum}}  |
        export-csv -Path "C:\change\Country.csv" -NoTypeInformation

[请考虑将Sort-Object cmdlet移至后面的管道...

© www.soinside.com 2019 - 2024. All rights reserved.