Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • Thank you! This is definitely more elegant than what I'd come up with. I got a way to deal with the quotes thanks to this [link] (sqlmovers.com/removing-quotes-from-csv-created-by-powershell) Is there a way to calculate a weighted average as opposed to 'normal' average'? The formula has been given as: sum((Lcy*Fcy))/sum(Fcy) So the ` Lcy*Fcy` should be done at individual row level to create a group sum. The group sum of the Lcy * Fcy is divided by the group sum of Fcy. Like this: ` lcyfcy[$2$3]+=($4*$5);fcy_tot[$2$3]+=$4; {avgexch=lcyfcy[i]/fcy_tot[i]; `
    – masterl
    Commented Apr 11, 2019 at 13:13
  • Let me see if I got that right the sum of the products of Fcy*Lcy (per row in the group) divided by the sum of sum of Fcy , I'll post an edit in a minute.
    – LotPings
    Commented Apr 11, 2019 at 14:14
  • the sum is row in the file not row in the group: So for each row we need to get the products of Fcy * Lcy before grouping them. I think an additional field is required to hold the value of Fcy * Lcy on the original file. Then use measure-object sum to divide the 2 sums.
    – masterl
    Commented Apr 11, 2019 at 14:33
  • I disagree, a sum per file would intermix currencys.
    – LotPings
    Commented Apr 11, 2019 at 14:38
  • 1
    The consolidation is also per currency so it will not intermix the currencies. I have solved it by adding an extra field in the csv: ` Import-Csv .\text.txt -Delimiter "|" | Select-Object *,@{Name='LcyFcy';Expression={[long]$_.Lcy*[long]$_.Fcy}} ` The result of this is then piped to the script from LotPings
    – masterl
    Commented Apr 11, 2019 at 14:54