Obtain unique two column

Hi,

The image shows a spreadsheet with two columns, "Arrival" and "Departure," listing various European cities such as Berlin, Prague, and Paris. (Captioned by AI)

I have this data. How can I obtain like this.

image

Arrival and Departure are unique. Below code works for “Arrival” column I want to add Departure column too.

data.AsEnumerable().GroupBy(Function(a) a.Field(Of String)(“Arrival”)).Select(Function(c) c.First).CopyToDataTable()

Hi @Murat

Can you try the below query

DT = DT.DefaultView.ToTable(True, "Arrival", "Departure")

Regards,

1 Like

Hi @Murat ,
To create a DataTable that contains unique rows based on both the “Arrival” and “Departure” columns using LINQ
dt_old.AsEnumerable() _
.GroupBy(Function(row) New With {Key .Arrival = row.Field(Of String)(“Arrival”), Key .Departure = row.Field(Of String)(“Departure”)}) _
.Select(Function(g) g.First()).CopyToDataTable()

image
The image is a screenshot of an Excel spreadsheet showing an "Arrival" and "Departure" schedule for three locations: Kochi, London, and Dubai. (Captioned by AI)

Regards,
Sneha

1 Like

If there’s only 2 columns, wouldn’t a simple Remove Duplicate Rows activity in Programming → DataTable work?

@Murat

The same cna be extended

data.AsEnumerable().GroupBy(Function(a) a("Arrival").ToString + a("Departure").ToString).Select(Function(c) c.First).CopyToDataTable()

also as mentioned above if only two columns then use remove duplicate rows

cheers

1 Like

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