1

Hello I Used below code to Merge CSV files using one common Key for adding one column from Child.CSV to Parent.CSV.

    {
        Import-Csv "D:\CSV check\Sourcecount.csv" -Header Sourcecount, MONTH_YEAR | ForEach-Object -Begin {
            $Employees = @{}
        } -Process {
            $Employees.Add($_.MONTH_YEAR,$_.Sourcecount)
        }

        Import-Csv "D:\CSV check\RenameFinal.csv" | ForEach-Object {
            $_ | Add-Member -MemberType NoteProperty -Name Sourcecount -Value $Employees."$($_.MONTH_YEAR)" -PassThru
        } | Export-Csv -NoTypeInformation "D:\CSV check\sourcefinal.csv"
    }

Question: Can you please help for the scenario joining for getting one column value from child.csv to Parent.csv for two common keys (by data and by userid).

Madhuri
  • 11
  • 4

1 Answers1

0

Below is the code I used to solve the above Query:

$f2=Import-Csv "D:\Sourcecount.csv" -Header Sourcecount,MONTH_YEAR,UserID
$f1= Import-csv "D:\Final.csv" -Header MONTH_YEAR,DestinationCount,UserID,Result,SourceCount

$f1|
%{
  $Month_YEAR=$_.MONTH_YEAR
  $UserID=$_.UserID
  $m=$f2|?{$_.MONTH_YEAR -eq  $Month_YEAR}|?{$_.UserID -eq  $UserID}
  $_.SourceCount=$m.Sourcecount
}
$f1| Export-Csv "D:\SourceFinal.csv" -NoTypeInformation
Merrill Cook
  • 988
  • 1
  • 8
  • 18
Madhuri
  • 11
  • 4