Sort data table activity not working

Hi,

I have used sort data table activity and it is not working as expected.

is there any linq and one liner code available to sort data table?
I need to sort the data table with Aging column (highest to lowest value)

Sample data:
image

1 Like

Hi

Hope the below expression would help you resolve this, use a assign activity like this

dt = dt.AsEnumerable().OrderBy(Function (a) Convert.ToDouble(a(“Aging”)).Select(Function (b) b).ToArray.CopyToDatatable()

If you want to run descending order then try like this

dt = dt.AsEnumerable().OrderByDescending(Function (a) Convert.ToDouble(a(“Aging”)).Select(Function (b) b).ToArray.CopyToDatatable()

Cheers @vigneshnkv

As an alternate we can use the Query Syntax with focus on readability:

(From d in dtData.AsEnumerable
Order by Convert.ToDouble(d(“Aging”).toString.Trim) Descending
Select r =d).CopyToDataTable