I am trying to determine if there\'s an easier way to write a Powershell function that groups an array by multiple properties and sums specified properties in the group, sim
I have the same, perhaps a bit simpler, I remove two |
$grouped = $ungrouped | group ID, ID2
$grouped | foreach {
$b= $_.name -split ', '
[pscustomobject] @{
ID = $b[0];ID2 = $b[1]
'Sum Value' = ($_.group | measure value -sum).sum
}
}
One liner :
Import-Csv 'YourFile.csv' | Group-Object -Property ID,ID2 | % {$b=$_.name -split ', ';$c=($_.group | Measure-Object -Property value -Sum).Sum;[PScustomobject]@{ID=$b[0];ID2=$b[1];Sum=$c}}