Sum a CSV property with PowerShell
Build a paste-ready command, then review its compatibility and effects before running it.
(Import-Csv <file> | Measure-Object -Property <property> -Sum).SumComplete required fields to copy the generated command.
read-onlyno known side effects Compatibility
WindowsVerified for Windows using powershell syntax.
Operational knowledgereview due 2027-05-13
RequirementsPowerShellRun inside PowerShell (pwsh), with Import-Csv and Measure-Object available from Microsoft.PowerShell.Utility; this is not Bash syntax.CSV inputA readable comma-separated CSV with the selected header and numeric values. Do not infer a valid total from a missing column or conversion errors.
Version supportPowerShell 7.xThe fixture and generated command were checked with PowerShell 7.6.9. No Windows PowerShell 5.1 execution is claimed.
Expected signals18432.75Representative successful output; values vary with the selected target and system state.
Known errorsCannot find pathThe selected CSV path does not exist or cannot be resolved from the current directory.Input object is not numericA selected value cannot be measured as a number. Inspect the original value, delimiter and decimal notation; do not silently discard invalid rows.The propertyVerify the selected property against the actual CSV header. A missing or misspelled column must not be accepted as a zero total.
VerifyImport-Csv {{file}} | Measure-Object -Property {{property}} -SumFor the documented Amount fixture (6000 and 12432.75), Count is 2 and Sum is 18432.75, without errors. For your file, reconcile the measured row count and total with independently checked numeric values; a zero or partial result alone is not proof of valid input.Rollback noteNot required: this command is read-only and does not change system state.
Command breakdown
01(GroupingEvaluates the import and measurement pipeline before reading its result.
02Import-CsvRead CSV rowsCreates an object for each data row; column headers become property names. The default separator is a comma.
03<file>CSV pathThe readable CSV file, including its header row. Use the File field to quote paths containing spaces.
04|Object pipelinePasses imported row objects, not formatted table text, to Measure-Object.
05Measure-ObjectNumeric aggregationMeasures the selected property across the input rows.
06-Property <property>Column selectionSelects the CSV header to aggregate, such as Amount. Confirm the exact header and numeric data first.
07-SumCalculate totalRequests the sum in the measurement result. It is a switch, separate from the closing parenthesis and member access.
08).SumRead the result propertyCloses the grouped pipeline and returns only its Sum property rather than the full measurement object.
For a comma-separated file with header Amount and rows 6000 and 12432.75, the total is 18432.75. Check delimiter, missing values and numeric conversion errors before trusting a total. This convenience aggregation is not an exact-decimal financial ledger.
Example input
(Import-Csv .\invoices.csv | Measure-Object -Property Amount -Sum).Sum
Illustrative output — exact values vary by system and data.
Official sources