Linq query regarding distinct rows

Hello everyone,

I have an excel file with multiple columns say ‘posting date’, ‘invoice’, ‘PO’ etc. i want a linq query that takes out all the distinct rows from the column ‘PO’

thanks in advance !!

Distinct Based on the specific column name from the data table.

DataTable dt=dt.DefaultView.ToTable(true, "DEPARTMENT")
or
DataView view = new DataView(table)
DataTable distinctValues = view.ToTable(true, "Column1", "Column2" ...)
or
DataTable =DataTable.DefaultView.ToTable(true)

regards,
Vishal

1 Like

thanks for the reply @vishal.kp but will this given the respective rows based on a specific distinct column??

Yes, this will return all the distinct elements in a particular column.

hello @vishal.kp, these are returning me only the specific column, i want that in respect of that particular column the rows are also fetched i.e. respective rows also based on that distinct vales of columns.

Thanks!!

@Palaniyappan can you guide ?

hello @Shikhar_Tandon
Can you give us more details of what do you want exactly ? also can you share the excel file and its desired output form

Also check this post if thats what you need

hi @vickydas thanks for the reply, i want a way to get all the distinct rows from a datatable say for ex. their is a datatable DT1 i want to get all the distinct rows from the table DT1 and store that somewhere else or filter it.
i dont want to remove them

thanks!!

Hello @Shikhar_Tandon

Do you want something like this ?

Datarowcomparer.xaml (8.0 KB)

@Shikhar_Tandon
you mentioned that the PO Column is triggering if a row is to rate as a Single or Multiple occurance

PFA demo XAML show casing some scenarios to handle this
Shikhar_Tandon.xaml (10.0 KB)

Let us know your feedback