September 5, 2017 at 8:23 am
This should be simple, but I'm having trouble with suming values across groups:
$a = @()
$b = New-Object pscustomobject -property @{TypeName = "Type A"; TypeId = "12"; Calls = 43}
$a += $b
$b = New-Object pscustomobject -property @{TypeName = "Type A"; TypeId = "12"; Calls = 12}
$a += $b
$b = New-Object pscustomobject -property @{TypeName = "Type B"; TypeId = "34"; Calls = 11}
$a += $b
$b = New-Object pscustomobject -property @{TypeName = "Type B"; TypeId = "34"; Calls = 17}
$a += $b
$a gives
TypeId TypeName Calls
------ ----- -----
12 Type A 43
12 Type A 12
34 Type B 11
34 Type B 17
I want to group by TypeId, TypeName to get
TypeId TypeName Calls
------ ----- -----
12 Type A 55
34 Type B 28
When I do
$Data2 = $Data | Group-Object -Property TypeName, TypeId|
%{New-Object psobject -Property @{
Item = $_.Name
nCalls = ($_.Group | Measure-Object nCalls -Sum).Sum
}
}
i get Item nCalls
12, Type A 55
34, Type B 28
How can I get the original properties as columns?
September 5, 2017 at 12:19 pm
Found the solution here: https://stackoverflow.com/questions/30769809/powershell-group-by-multiple-properties
Clunky...
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy