I am trying to sort the data present in the DataTable by Year in descending order and month in ascending order. But it is not sorting data as expected.
Code used for this as as below
DataTable sortedtTable = currentBalanceData.AsEnumerable().OrderByDescending(x => x.Field<DateTime>("Date").Year).ThenBy(x => x.Field<DateTime>("Date").Month).CopyToDataTable();
and output of the same is below
Let me know what I am doing wrong. Expected output is as below
2017 01
2017 02
2017 03
2017 04
2017 05
2017 06
2017 07
2017 08
2016 01
2016 02
2016 03
2016 04
2016 05
2016 06 ..... and so on.
Edit --> Sorting working only for year.
DataTable sortedtTable1 = currentBalanceData.AsEnumerable().OrderBy(x => x.Field<DateTime>("Date").Year).ThenBy(y => y.Field<DateTime>("Date").Month).CopyToDataTable();
output of the sortedtTable1 is as below