- Aug
- 2,037
- 82
Here is my method of adding up columns of a comma separated file (CSV)
The .csv file consists of four columns;
While the goal is to sum the Interest and Deposit columns, I also do other calculations to create a Total, which I can use from TCC.
I run the PowerShell Script from TCC;
I now have the total in a TCC environment variable;
Joe
The .csv file consists of four columns;
Code:
Account,Trans_Date,Interest,Deposit
While the goal is to sum the Interest and Deposit columns, I also do other calculations to create a Total, which I can use from TCC.
Code:
# tfsa.csv = Account,Trans_Date,Interest,Deposit
#
$TFSA = Import-Csv E:\Documents\vfp\tfsa\tfsa.csv
$Total = 0
$TotalInterest = 0
$TotalDeposit = 0
$TheSum = $TFSA | Measure-Object "Interest" -Sum
$TotalInterest = $TheSum.Sum
$TheSum = $TFSA | Measure-Object "Deposit" -Sum
$TotalDeposit = $TheSum.Sum
$Total = $TotalInterest + $TotalDeposit
$TotalInterest = "{0,9:C}" -f $TotalInterest
$TotalDeposit = "{0,9:C}" -f $TotalDeposit
$Total = "{0,9:C}" -f $Total
Write-Output "Total Interest = $TotalInterest"
Write-Output "Total Deposit = $TotalDeposit"
Write-Output " ---------"
Write-Output "Total = $Total"
$env:Total = $Total
I run the PowerShell Script from TCC;
Code:
pshell tfsa.ps1
Total Interest = $18.24
Total Deposit = $1,899.31
---------
Total = $1,917.55
I now have the total in a TCC environment variable;
Code:
echo %total
$1,917.55
Joe