Split and Sort Datatable

I need to sort the column based on ID .

Input is : ID Brand
k123-400 ABC
k122-400 QWE
k123-402 ASD
k122-401 ZXC

expected result is

ID Brand
k122-400 QWE
k122-401 ZXC
k123-400 ABC
k123-402 ASD

How to perform slip and do sorting using sort Datatable …Kindly help

@tharani.natarajan

Please try this in assign

dt = dt.AsEnumerable.OrderBy(function(x) Cint(x(0).ToString.Split("-"c)(1))).CopyToDataTable

cheers

1 Like

One of many options (we assume input 1 col datatable)

prepare result datatable with build datatable (2 cols) - dtResult

Assign Activity:
dtResult =

(From d in dtInput.AsEnumerable
Let arrSplit = d("ColName").toString.Trim.Split(" "c)
Let ra = arrSplit.Cast(Of Object).toArray
Order by arrSplit(0)
Select r = dtResult.Rows.Add(ra)).CopyToDataTable

we would do some addtional enhancements e.g. values cleansing, numerical ordering

@tharani.natarajan

dt_build.AsEnumerable.OrderBy(function(x) x(“ID”).ToString).CopyToDataTable

Cheers!!

@tharani.natarajan

input

ID Brand
k123-400 ABC
k122-400 QWE
k123-402 ASD
k122-401 ZXC

try this

yourDataTableVar = yourDataTableVar.AsEnumerable().OrderBy(Function(row) row("ID")).CopyToDataTable()

cheers…!!!

2 Likes

Hi @tharani.natarajan

sortedDt= (From row In dt.AsEnumerable()
                   Order By row.Field(Of String)("ID")
                   Select row).CopyToDataTable()


Refer the below workflow for better understanding
Sequence.xaml (8.3 KB)

Regards,

1 Like

Hello @tharani.natarajan

Try this Solution,
Data_Sort.1.0.1.Zip (32.3 KB)

1 Like

Hi @tharani.natarajan

Use below expression

DT = DT.AsEnumerable.OrderBy(Function(row) row(“ID”)).CopyToDataTable

Hope it will helps you :slight_smile:
Cheers!!

1 Like

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