I have an issue with features on excel file. I’m trying to remove the duplicate row in a data table. Sample of DT :
|First Name|Last name |ID|
|Brigite|Tabar|12345|
|Frederic|Alban|32415|
|Brigite|Tabar|67890|
I use this to remove duplicate row :
(From d in DT.AsEnumerable()
Group d By ld= d(“ID”),
into grp=Group
Select grp.First()).CopyToDatatable()
But with this the bot will remove the first line : |Brigite|Tabar|12345| and i want that the bot remove the first line and keep the second line in the DT : |Brigite|Tabar|67890| because the ID can be updated and i want to keep the most recent, so the last in the DT.
Your case is different, it looks like you do the grouping on firtname, Last Name is my understanding correct?
How would your expected output look like in such a scenario?
First Name|Last name |ID|
|Brigite|Tabar|12345|
|Brigite|Tabar|55555|
|Frederic|Alban|32415|
|Brigite|Tabar|67890|
(From d in DT.AsEnumerable()
Group d By k1= d(“FirstName”).toString.Trim,k1= d(“LastName”).toString.Trim
into grp=Group
Select grp.Last()).CopyToDatatable()
take care about “ while copy and past and change it to the corret ones
Statement is doing:
making groups by FName, LName
taking the last group member
I tried to do that but the lines are mixed, don’t know why… And i want to keep the same order (just without the first duplicate row).
I know that because i have a column with the date of the day and the bot run every day.
I tried to add something like “ORDER by” but no success and I have another issue about this date which change his format when i delete the range in the excel file and write the new DT in the same excel file for all the line which contain a “OK” on the status column…
Create an empty datatable
loop backwards through your data, starting at your last entry and working your way “back up”.
For each iteration, check if the current person is already in the new datatable:
if not: Add that person, including the ID, to the new datatable
@BCdev
you can order like below:
(From d In dtData.AsEnumerable()
Group d By k1= d(0).toString.Trim,k2= d(1).toString.Trim
Into grp=Group
Let r = grp.Last
Order By Array.IndexOf(dtData.AsEnumerable.toArray,r)
Select r).CopyToDatatable()
Kind of repeating the same thing, but if intent is to keep most recent duplicate, then sort the datatable by the column that has the most recent indicator (numeric sequence of an id or time created, etc) first, then remove duplicates.