mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-15 15:53:32 +00:00
directory renames
This commit is contained in:
42
Public/Invoke-Sum.ps1
Normal file
42
Public/Invoke-Sum.ps1
Normal file
@@ -0,0 +1,42 @@
|
||||
function Invoke-Sum {
|
||||
[CmdletBinding()]
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user