Hello,
i need to find the index values of rows with duplicate values in datatable and assign it to an Array

example: Mat 920 index (0,4)
Thank you
Hello,
i need to find the index values of rows with duplicate values in datatable and assign it to an Array

example: Mat 920 index (0,4)
Thank you
Hi @Yugal_Raju
Can you try this
(From row In dt.AsEnumerable()
Let val = row("Material").ToString().Trim()
Where dt.AsEnumerable().Count(Function(r) r("Material").ToString().Trim() = val) > 1
Select dt.Rows.IndexOf(row)).ToArray()
Regards,
Hello thank you ,
it is working but how would i modify the query to only get index of duplicate of “Mat-920”
Lets assume the data is read into a datatable
one of many options for:
Lets create a Dictionary which can be later be used for lookup / further processings
Assign Activity:
dictLKDupIndexes | DataType: Dictionary(Of String, int32()) =
(From d In yourDataTableVar.AsEnumerable()
Group d By k=d("Material").toString.Trim Into grp=Group
Let arrIdx = grp.Select(Function (x) x.Table.Rows.IndexOf(x)).toArray
Select t = Tuple.Create(k,arrIdx)).ToDictionary(Function (x) x.Item1, Function (x) x.Item2)
So we can get all Indexes for Mat-920 by:
dictLKDupIndexes("Mat-920")
And get all duplicated indexes by:
dictLKDupIndexes(“Mat-920”).Skip(1).ToArray
How about the following?
(From row In dt.AsEnumerable()
Let val = row("Material").ToString.Trim
Where val = Material AndAlso
dt.AsEnumerable().Count(Function(r) r("Material").ToString.Trim = val) > 1
Select dt.Rows.IndexOf(row)).ToArray()
Regards,