I have a CSV with:
Name, Quantity, Color
Item1,1,Black
Item2,1,White
Item1,2,Black
I would like to Group by name and color but also have the Count multiplied by the quantity to give me a Total. All works fine if the Quantity is always 1 on each one but when I had a quantity of 2 on the last one it does not account for that.
The output I am looking for is:
Item1,3,Black
Item2,1,White
But what I get is:
Item1,2,Black
Item2,1,White
This is what I am using to test (and learn
)
$Test = import-csv C:\Logs\Test.csv
$Testing = $Test | Group-Object Name |
Foreach-Object {
[pscustomobject]@{
Name = $_.Group[0].Name
Quantity = $_.Group[0].Quantity
Count = $_.Count
Total = ($_.Group[0].Quantity | Measure -Sum).Sum * ($_.Count | Measure -Sum).Sum
Color = $_.Group[0].Color
}
}
$Testing | ft
I am obviously a rookie at this but trying to learn as I go along. I know I probably have way to much code for what I need but using it to understand and how everything works.
Thanks,
Scott