Russell Herndon
Russell Herndon

Reputation: 15

Remove duplicate rows of data

Remove duplicate rows of data leaving one record with the fastest time

my data looks like this:

First Name Last Name    Fastest Time     Time To Cut
---------- ---------    --------         -----------
Jack       Black        01:31.00         33.497 should be removed    
Jeff       Black        01:27.22         29.718     
Mike       Fair         01:01.33         3.823  should be removed     
Mike       Fair         00:58.12         0.621      
Anthony    Gal          01:04.36         6.858      
Steff      Hart         01:06.50         8.999      
Steff      Hart         01:07.50         9.999  should be removed   

I am trying to get the fastest time for each person in the table. I have tried using Select-Object -Unique (with the table sorted on 'Last Name','First Name') but I can't figure out what to do from there.

Upvotes: 1

Views: 438

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174525

Use Group-Object to group the data by name, then select the best time from each group:

$data |Group-Object 'Last Name','First Name' |ForEach-Object {
    # Output only the fastest time from each group
    $_.Group |Sort-Object 'Fastest Time' |Select -First 1
}

Upvotes: 1

Related Questions