forked from dfinke/ImportExcel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Invoke-Sum.ps1
41 lines (30 loc) · 821 Bytes
/
Invoke-Sum.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function Invoke-Sum {
param(
$data,
$dimension,
$measure
)
if(!$measure) {$measure = $dimension}
$h=@{}
foreach ($item in $data){
$key=$item.$dimension
if(!$key) {$key="[missing]"}
if(!$h.ContainsKey($key)) {
$h.$key=[ordered]@{}
}
foreach($m in $measure) {
$value = $item.$m
if($value -is [string] -or $value -is [System.Enum]) {
$value = 1
}
$h.$key.$m+=$value
}
}
foreach ($entry in $h.GetEnumerator()){
$nh=[ordered]@{Name=$entry.key}
foreach ($item in $entry.value.getenumerator()) {
$nh.($item.key)=$item.value
}
[pscustomobject]$nh
}
}