我有一个这样的csv:
MPN,Per_Pallet,Customer_Order,Customer_Order_Date,Backordered_by_Pallet,Reserved_Sum
501,116.82,12055,4/28/2021,3.18,1.02
501,116.82,12421,6/7/2021,2.36,1.02
501,116.82,12424,6/7/2021,3.91,1.02
2243,30,12014,4/26/2021,1.4,1
2243,30,12425,6/7/2021,4.8,1
2243,30,12817,7/21/2021,0.4,1
2243,30,13359,9/29/2021,0.6,1
2435,50.22,12014,4/26/2021,1,2
2435,50.22,13311,9/24/2021,1.14,2
218,40,13236,9/15/2021,3,5
218,40,13382,10/4/2021,3,5
7593,64,12670,7/2/2021,5,5
484,8,12582,6/22/2021,0.38,2
484,8,12798,7/16/2021,1.38,2
484,8,13255,9/18/2021,1,2
484,8,13288,9/22/2021,1,2
5647,87,13304,9/23/2021,0.01,1
我需要按 MPN 列分组,然后首先检查最早的订单,看看 Backordered_by_Pallet 是否大于或等于 Reserved_Sum。
如果是 -cge,则只显示该组的那一行。如果不是,则检查下一个订单和第一个订单是否是并显示它们,依此类推。直到 backored 总数大于 Reserved_Sum
这就是我脑海中的样子:
look at oldest order first for matching MPN
if oldest orders Backordered > Reserved Sum
Then only display oldest order
Else if oldest order + second oldest order > Reserved Sum
then display both orders
Else If Less Than, Add Next Order etc
预期输出:
MPN,Per_Pallet,Customer_Order,Customer_Order_Date,Backordered_by_Pallet,Reserved_Sum
501,116.82,12055,4/28/2021,3.18,1.02
2243,30,12014,4/26/2021,1.4,1
2435,50.22,13311,9/24/2021,1.14,2
218,40,13236,9/15/2021,3,5
218,40,13382,10/4/2021,3,5
7593,64,12670,7/2/2021,5,5
484,8,12582,6/22/2021,0.38,2
484,8,12798,7/16/2021,1.38,2
484,8,13255,9/18/2021,1,2
5647,87,13304,9/23/2021,0.01,1
我有不同的工作,但我不知道如何把它们放在一起:
如果它更大或不是很容易返回:
$Magic | ForEach-Object {
If ($_.Backordered_by_Pallet -cge $_.Reserved_Sum) {$_}
Else {"Nothing To Order"}
}
我已经尝试通过添加一个组
$Magic | Group-Object MPN | ForEach-Object {
If ($_.group.Backordered_by_Pallet -cge $_.group.Reserved_Sum) {$_}
Else {"Nothing_Left_To_Order"}
}
但这会显示整个组或什么都没有,我不确定如何将它们组合在一起,更不用说如何在需要时添加前一行的数量。
我相信我需要为每个深度做几层,所以我对 MPN 进行分组,为那个 mpn 创建一个数组,然后为该数组上的每个创建一个数组(按最旧排序)(不知道如何将前一行拉到add) 然后只导出结果,然后循环移动到下一个组,依此类推。
像这样?我知道这不是真的,我就是想不通
$Magic_Hash = $Magic_File | Group-Object -Property MPN -AsHashTable | Sort $_.group.Customer_Order_Date
ForEach ($item in $Magic_Hash) {
If ($item.group.Backordered_by_Pallet -cge $_.group.Reserved_Sum) {$_}
Elseif ($item.group.Backordered_by_Pallet + $item.group.Backordered_by_Pallett["2nd oldest order"] -cge $_.group.Reserved_Sum) {$_}
else {"Nothing_Left"}
}
```
Thank you so much for all your help this community is amazing