I have a column in datatable,need to sort the column oldest to newestaccording to the year,month and number.
Below is the table
Id
ISS-2023JUL-0023
ISS-2023JAN-0012
ISS-2023APR-2880
ISS-2022JAN-1234
ISS-2022APR-3425
And the output after sort should be like below.
Id
ISS-2022JAN-1234
ISS-2022APR-3425
ISS-2023JAN-0012
ISS-2023APR-2880
ISS-2023JUL-0023
Please help me to solve this.
@yashashwini2322
did you try sort datatable activity.
Read the data from your Excel file and store it in a DataTable, let’s call it “inputDataTable”.
Use the “Sort Data Table” activity to sort the “Id” column in ascending order. Configure the activity as follows:
Input: Set it to “inputDataTable”.
Output: Create a new DataTable variable, let’s call it “sortedDataTable”.
Sort Order: Select “Ascending”.
Column Sort:
Column Name: Set it to “Id”.
Sort Order: Select “Ascending”.
The “sortedDataTable” will now contain the sorted data. You can use the DataTable in
ppr
(Peter Preuss)
July 4, 2023, 12:28pm
3
Assign Acitivity
dtOrdered =
(From d in YourDataTableVar.AsEnumerable()
Let sd = d("Id").ToString.Trim
Let sp = System.Text.RegularExpressions.Regex.Match(sd, "(?<=\-).*?(?=\-)").Value
Order by CDate(sp).DateTime
Select r=d).CopyToDataTable
ppr
(Peter Preuss)
July 4, 2023, 12:38pm
4
Yash:
year,month and number.
Extending above to also incude the number we can do:
dtOrdered =
(From d in YourDataTableVar.AsEnumerable()
Let sd = d("Id").ToString.Trim
Let sp = System.Text.RegularExpressions.Regex.Match(sd, "(?<=\-).*?(?=\-)").Value
Let np = System.Text.RegularExpressions.Regex.Match(sd, "(?<=\-)\d+?$").Value
Order by CDate(sp).Date, CInt(np)
Select r=d).CopyToDataTable
1 Like
I tried but it’s giving the error …datetime is not a member of date
@yashashwini2322
Try this one
dt.AsEnumerable().OrderBy(Function(row) DateTime.ParseExact(row("Id").ToString().Substring(4, 7), "yyyyMMM", CultureInfo.InvariantCulture)) .ThenBy(Function(row) Integer.Parse(row("Id").ToString().Substring(11))) .CopyToDataTable()
ppr
(Peter Preuss)
July 5, 2023, 11:12am
7
Order by CDate(sp).Date, CInt(np)
refer to the updated LINQ
1 Like
ppr
(Peter Preuss)
July 6, 2023, 7:37am
9
system
(system)
Closed
July 9, 2023, 7:38am
10
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.