Remove duplicate rows based on a value from a single data column

I want to remove duplicate rows from a datatable if a particular column1 value is duplicate in other rows.

dtOutput=dtOutput.DefaultView.ToTable(True,“column1”)

when I try this it removes all the columns as well, but I need the rest of the columns.

1 Like

@banerjeerules check attached file i hope its useful

RemoveDuplicatesInSingleColumn.zip (12.8 KB)

22 Likes

You can try filter data activity if feasible

1 Like

Thanks this works in getting the datatable sorted, but when I write the data table on the same excel sheet the remaining rows stays back… if I write on a different sheet it is fine. Can you tell me how can I write on the same sheet from where I am picking it up.

You need to first clear the Excel sheet. As read range will just overwrite the already present rows. Use hot keys to clear the excel sheet first then use a write range.

Below are the steps

Use Excel Application scope
Select Range ->Menstion the sheet name and Range->“A1”
use Send hot key → ctrl+A (Provide selector to the excel sheet)
use Send hot key → delete
use Send hot key → ctrl+s
Then use Write Range with your filtered DataTable.

2 Likes

@indra using your code I get the following error Assign : Unable to cast object of type ‘System.Double’ to type ‘System.String’. Can you help

@banerjeerules Do you change code in assign activity ?

1 Like

I changed the whole excel to text format now it works

2 Likes