counts totals in multiple .csv files
top of page

counts totals in multiple .csv files


Lazy Win Admin has posted a PowerShell script here that you can use to add up totals given in column A for values in column B in multiple .csv values. The script will compile the counts given in column A even when there are duplicate entries in column B.

So in this example I have two .csv files which show the number of home runs each major league baseball player hit each season (Batting.csv) and how many home runs each player hit in each post season series (BattingPost.csv).

Enter the script below into PowerShell ISE (x86), and be sure to edit it so it includes the path to the directory with your .csv files and matches in the headings in the files.

The script will generate a new window adding up the numbers in the first column for each unique entry in column B.

Get-ChildItem -Path C:\FooFolder\powershell\*.csv | # Get each CSV files ForEach-Object -Process { Import-Csv -Path $PSItem.FullName # Import CSV data } | Group-Object -Property Name | # Group per Domain Name Select-Object -Unique -Property Name, @{ Label = "Sum"; Expression = { # Sum all the counts for each domain ($PSItem.group | Measure-Object -Property Count -sum).Sum } } | Sort-Object -Property Sum -Descending | Out-GridView -Title "Top Domains"


bottom of page