How to Find Unique Rows

i have a excel file, with multiple columns i want to write unique rows in sheet2

Sample input:

image

Expected :slight_smile:

image

Hi @gantamohan502

dt1.AsEnumerable().GroupBy(Function(row) row("CityId")).Select(Function(group) group.First()).CopyToDataTable()

@gantamohan502

uniqueRows = (From row In dtInput.AsEnumerable()
                  Select row).Distinct(DataRowComparer.Default).CopyToDataTable()

In assign activity Try this linq query

Hii @gantamohan502

Try this query:

(
From row In DT_input
Group row By a = row("CityId").ToString.Trim Into grp = Group
Select grp.First
).CopyToDataTable

Cheers

Hi @gantamohan502

Try this

DT = DT.AsEnumerable().
    GroupBy(Function(row) row("CityId").ToString).
    Select(Function(g) g.First()).CopyToDataTable()

Input:

image

Output:

image

Regards,

Hi @gantamohan502

You can achieve it by using the LINQ Expressions,
→ Use Read Range workbook activity to read the excel and store in a datatable called Input_dt.
→ Then insert the assign activity and give the below LINQ Expression,

- Assign -> Output_dt = Input_dt.AsEnumerable.GroupBy(Function(X) New With { Key .Column1 = X("CityId"), Key .Column2 = X("CityName") }).Select(Function(Y) Y.First).CopyToDataTable()

→ Then use the write range workbook activity to write the Output_dt to the excel.

By using LINQ Expressions also we can remove the duplicte rows in the excel.

Hope it helps!!

Hi @gantamohan502

dt1.AsEnumerable().GroupBy(Function(row) row("CityId")).Select(Function(group) group.First()).CopyToDataTable()

image
Input
image
Output
image

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.