Sorting of column

If I have a column named Total with values such as 50,-100,600, -600,100, -50 and I need the final result of column Total to be 50,-50,100,-100,600,-600.

Did you try Sort Datable activity

yes , but did not get the desired output

Give a try at the following:

dtSorted =

(From d in YourDataTable.AsEnumerable
Let it = CInt(d("Total").toString.Trim)
Group d by k = Math.Abs(it) into grp=Group
Order by k
From g in grp
Order by CInt(g("Total").toString.Trim) DESCENDING
Select r = g).CopyToDataTable
1 Like

Try This:

sortedDataTable = (From row In inputDataTable.AsEnumerable()
                   Order By Math.Abs(CInt(row("Total"))) Ascending
                   Select row).CopyToDataTable()

1 Like

its working thanks you

1 Like

Can you check for us also with this set?
-50,-100,-600, 600,100, 50

As from description you would expect:
50,-50,100,-100,600,-600 in exact this ordering, right?

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