Ray_Sha1
(Ray Sha)
January 11, 2023, 8:02am
1
I have a list of values, and I want to count of the similar value in the list stored In data table.
Ex:
Input:
ListA={apple, apple, banana, apple, cat, banana, dog}
Output:
Col1. col2
apple. 3
banana. 2
cat. 1
dog. 1
I need a linq query that achieves the above output?
Possible??
sarathi125
(Parthasarathi)
January 11, 2023, 8:24am
2
@Ray_Sha1 ,
The below code you can use it to get the name and count of the element in the list. It will return as a dictionary type
ListA.GroupBy(Function(x) x).ToDictionary(Function(x) x.Key, Function(x) x.Count())
Yoichi
(Yoichi)
January 11, 2023, 8:25am
3
Hi,
Can you try the following sample?
First, define dt which has 2 columns using Build DataTable activity.
Then
dt = yourList.GroupBy(Function(s) s).Select(Function(g) dt.LoadDataRow({g.Key,g.Count},False)).CopyToDataTable()
Sequence.xaml (8.0 KB)
Regards,
HI @Ray_Sha1
Checkout this expression
(From d In sample
Group d By k=d.ToString.Trim Into grp=Group
Let f= grp(0)
Select Dt.rows.Add(f,grp.count.ToString)).CopyToDataTable
Regards
Sudharsan
1 Like
system
(system)
Closed
February 9, 2023, 4:46pm
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.