How to remove duplicate

Hello,

i have data like below

my expected output is like below
image

how can i achieve this ?
help me on same

Use the “Group By” LINQ expression

dtOutput = (From row In dtInput.AsEnumerable()
            Group row By ProjectKey = row("Project Key") Into Group
            Select dtInput.Clone().Rows.Add(ProjectKey, Group.Sum(Function(r) Convert.ToInt32(r("Hour Total"))))).CopyToDataTable()

@Mathkar_kunal

Try using DefaultView in assign activity like this

dtUnique = yourDataTable.DefaultView.ToTable(True)

Hi @Mathkar_kunal ,

Try this:

dt.DefaultView.ToTable(True) - removes duplicate rows by comparing all columns in the DataTable.

dt.DefaultView.ToTable(True, “Project Key”, “Hour Total”) → removes duplicates only based on the specified columns (Project Key, Hour Total) and returns a table with just those columns.

dt - your datatable name

1 Like

Datatable.DefaultView.ToTable(True) is the fucntion you can use

1 Like

it is not removing duplicates
check below ss


i am reading range from sS1:T2000 and saving i variable DT5
and using same in function and writing table again from J1

but you can see it is showing me full column data
my expected output is

write dtunique not dt5

@Mathkar_kunal,

You are writing the original datatable to excel file. Code will not update the original datatable but will return the unique data into dtUnique datatable.

Write dtUnique datatable with Write Range.

1 Like

Hello @Mathkar_kunal

Use below solution

step 1 : read input excel sheet as per your data (define output variable “DT”)

step 2 : assign key = DT and Value = DT.DefaultView.ToTable(True)

step 3 : Write new update DT data in another excel sheet, check your output

1 Like

Hi @Mathkar_kunal

You can consider below approach:

  1. read range activity to read data from excel and save it in a datatable

  2. remove duplicate rows activity to remove the duplicates from the datatable

  3. write range activity to write the datatable retrieve in step 2 to excel

Hope this helps.

1 Like

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