[UiPath] Helpful DataTable methods and queries for better sorting, filtering, extracting

Here are a couple of handy DataTable.Select queries that I found useful in managing data tables. I have previously discussed about How to filter multiple dynamic values in a datatable column but this time I'm going to collect my most used ones for future reference.
How to select distinct values in a row

OutputDT = DataTable.DefaultView.ToTable(true,"ColumnName")

Returns a datatable with distinct values from a specific column. This is similar to running a Remove Duplicate Rows activity except you can directly specify which column to affect.

How to sort data table using multiple columns

DataTable = (From x In DataTable.AsEnumerable() Order By convert.Tostring(x("ColumnName1")),convert.ToString(x("ColumnName2")) Select x).CopyToDataTable

Returns a data table sorted in ascending order by 2 columns. This is similar to running a Sort Data Table activity except that you can use multiple sorting columns.

How to query your datatable using Select method

OutputDT = DataTable.Select("[Column Name] IN ('Value1','Value2','Value3')")

This will return rows where the specified column contains the indicated values. Similar to filtering a table from Excel.

RelatedHow to filter multiple dynamic values in a datatable column

Just a few so far but will add to these as I go along learning UiPath better! :)
Share: