How to sort a datatable by two columns?

I have an Excel file with the a data table, and it has 4 columns: ID, Month, Location, and Score. I want to sort this table by 2 columns, in the correct order. First, sort the entire table by Location, and then after that, sort it by Month.

I was thinking about using Sort DataTable activity, but it seems to sort only one column. If I use two Sort DataTable activities, the second activity will most likely mess up the sorted datatable by the first activity, and this is not what I want.

I need to apply two kinds of sorting to the table. I will attach an image of the original unsorted datatable, and the sorted datatable. How could I do this?

The left is the original unsorted one. The right is what I want.
image

1 Like

Hi @tomato25
Kindly try with this query
datatablevariable = From x In datatablevariable.AsEnumerable() Order By convert.Tostring(x(“Location)”),convert.ToString(x(“Month”)) Select x).CopyToDataTable

For more info on this
Sort Excel by multiple column

Cheers @tomato25

7 Likes

image

It is giving an expression error…

Never mind. I noticed it is missing the starting parenthesis.
Thank you for your help!

1 Like

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