这是我刚才提出的一个相关问题(Powershell Grouping of csv import file)
但可能有足够的不同以保证一个新问题!
我有一个与此类似的csv文件:
Employee ID, Entry Date, Product Code,Amount Due
0001,20/11/2017,A001,10
0001,20/11/2017,Q003,13
0001,20/11/2017,H001,8
0002,20/11/2017,P003,12
0002,20/11/2017,A001,7
当我运行以下代码(此处的代码段)时:
$csvfile=import-csv $files
$csvfile | group-object "Employee ID" |
ForEach-Object {
$first_line="Y"
$EmployeeID = ($_.Group.'Employee ID' | Select -First 1)
if ($_.Group.'Employee ID' -ne "Employee ID")
{
$date = Get-Date -format "yyyyMMdd"
$DateStr = '{0:yyyyMMdd}' -f $date
if ($first_line="Y")
{
$Sum = ($_.Group | Measure-Object 'Journal Net of Total Adjusted Reclaim Tax' -Sum).Sum
$TaxSum = (($_.Group | Measure-Object 'Report Entry Total Reclaim Adjusted Amount' -Sum).Sum /2)
$SumMinusTax=$Sum - $TaxSum
$datestr_report='{0:yyyyMMdd}' -f $Item.'Batch Date'
$myoutput="E;S4000;INV;;{3};{2};PLE;4;{4};{6};{2};{3};GB01NETBACS;Expenses;GBP;;DMG;;0;;;;;;;;;;;;;;;;;{7};{9}" -f $_.Name, $EmployeeID , $Item.'Employee ID', $DateStr, $Item.'Report Name', ";", $Item.'Report Submit Date', $SumMinusTax,$Item.'Branch',$TaxSum #";" $Sum #$date
write-output $myoutput | out-file -filepath $outputfile -append -encoding ASCII
$first_line="N"
}
$ EmployeeID变量只会赶上下一轮 - 所以总是一步一步地
我错过了一些明显的东西吗?