https://github.com/americanhanko/columnmapper
A simple VLOOKUP-like function that can handle duplicates.
https://github.com/americanhanko/columnmapper
csv duplicate-detection duplicates vlookup
Last synced: about 1 month ago
JSON representation
A simple VLOOKUP-like function that can handle duplicates.
- Host: GitHub
- URL: https://github.com/americanhanko/columnmapper
- Owner: americanhanko
- License: mit
- Created: 2019-04-10T18:28:05.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-23T17:40:39.000Z (over 5 years ago)
- Last Synced: 2025-02-26T23:26:50.676Z (8 months ago)
- Topics: csv, duplicate-detection, duplicates, vlookup
- Language: PowerShell
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ColumnMapper
Consolidate duplicate row values and create new columns for each unique value found in a corresponding column.
## Getting Started
The `ColumnMapper` module exports a single function `Invoke-ColumnMapper` and an alias to it `cmap`. It requires one parameter `InputPath` which may be an absolute or relative path to the input CSV file containing the data you wish to map.
To install the `ColumnMapper` module, open PowerShell and run the following command:
```powershell
Install-Module -Name ColumnMapper -Scope CurrentUser
```## Usage
### Basic
Using the function:
```
Invoke-ColumnMapper -InputPath C:\path\to\data.csv
```or using the alias:
```
cmap -InputPath C:\path\to\data.csv
```### Full Syntax
```powershell
Invoke-ColumnMapper [[-InputPath] ] [[-KeysHeader] ] [[-OutputPath] ] [[-ValuesHeader] ] [-NoExport] [-Open] []
```### Parameters
-InputPath
The absolute or relative path to the input CSV file.-KeysHeader
Specifies the column name to search in for the row identifiers.
ColumnMapper will use these values as the primary row identifiers.
Defaults to '[PO] Order Id' for legacy purposes.-ValuesHeader
Specifies the column name to search for unique values mapped to the row identifiers.
ColumnMapper will take any value found in the first column and create new columns
for each unique value found in this one. Defaults to '[PO]GL Account (GL Account Id)'
for legacy purposes.-OutputPath
Specifies the path to write the output CSV file to.
Defaults to ColumnMap_YYYYMMDD.csv-Open []
Opens the output CSV file.
Defaults to false.### Getting Help
As with most functions and cmdlets, you can use the `Get-Help` cmdlet. To see help for `Invoke-ColumnMapper`, run:
```powershell
Get-Help Invoke-ColumnMapper
```## Example
Let's say you have the file **People.csv**:
| Names | FavoriteSport |
|-------|---------------|
| Bob | Basketball |
| Bob | Baseball |
| Alice | Basketball |
| Alice | Tennis |
| Alice | Volleyball |
| Alice | Volleyball |Pass the file to `Invoke-ColumnMapper` and specify the **Names** and **FavoriteSport** columns, and you'll get a new CSV file that looks like this:
| Names | FavoriteSport | | |
|-------|---------------|----------|------------|
| Bob | Basketball | Baseball | |
| Alice | Basketball | Tennis | Volleyball |The invocation in PowerShell would look like this:
```powershell
PS C:\Users\americanhanko> Import-Module Invoke-ColumnMapper
PS C:\Users\americanhanko> Invoke-ColumnMapper -Path .\People.csv -KeysHeader Names -ValuesHeader FavoriteSport
Output file is here: C:\Users\americanhanko\ColumnMap_20190416.csv
```## Detailed Explanation
`Invoke-ColumnMapper` finds all unique values in the column specified by the `KeysHeader` parameter and converts them to hash keys. When it finds a new key,
it asks for any values found in the column specified by the `ValuesHeader` parameter and adds them to a new array. It continues to add any new values
found in the `ValuesHeader` column to each corresponding array. Finally, we split the array into a comma-separated string so that it can be imported
easily into your favorite spreadsheet application.