hacky
(NotHacker)
October 20, 2022, 10:41am
1
Hi Team,
Suppose I am having a datatable as shown below:
Name
Age
A
20
B
25
C
30
D
35
I need to use a LINQ to filter the datatable such that I have a value in a variable using single assign activity
Eg:
String Result = Datatable.AsEnumerable().select (such that Name =“C”)
Somehow I need to have Value 30 in the result string.
Expectation : Result = 30
Gokul001
(Gokul Balaji)
October 20, 2022, 11:04am
2
Hi @hacky
Welcome to UiPath community
You can try to achieve via Filter DataTable activity
Check out this XAML file
FiterBasedInput.xaml (9.3 KB)
Regards
Gokul
HI @hacky
You can try with lookup datatable activity
Regards
Sudharsan
Gokul001
(Gokul Balaji)
October 20, 2022, 11:09am
4
Hi @hacky
You can try with LINQ expression
DtBuild.AsEnumerable.Where(Function(r) r("Name").ToString=InputVal).CopyToDataTable
Regards
Gokul
ppr
(Peter Preuss)
October 20, 2022, 11:17am
5
we can do as above, also demonstrated the handling of empty filter result
I many scenarios it is prefered to create a lookup dictionary and take some benefits of
performance
keys checking
…
Hi @hacky
Remember that LINQ expression usually returns innumerable collections, you can get the first returned value if you know there is always a unique response.
Filtered_age = dt_variable.AsEnumerable().Where(function (dr) dr(“Name”).ToString=“C”).First().Item(“Age”)
Bests,
Andres
Str=DT.Asenumarable.Where(Function(r) r(“Name”).Tostring=“C”).First().item(“Age”).Tostring