FILTER AND COUNT WITH LINQ

Good Morning ! Guys, I’m building a flow with the help of LINQ, I have a question, can I pull a table without reference?

texte linq.xaml (8.1 KB)

LINQSAIDA.AsEnumerable.Count(function (A) A(“C”).ToString=(“MG”)) > can I pull all the cells and count the ones that repeat?

Example: MG 2, MA 1 AND MS 2

we would like to inform that the LINQ count operator in VB.Net is critical and only partly implemented within the platform. We can rewrite with a Where and counting the results like:
Where(Function (x) …).Count

it could be the case that you are looking for a group by and counting the resulting group members.

Can you share some sample data?
refered to the datatable form your XAML

Hi @Luan ,
Use below select query to get the details.
Dt.Select("ColumnName in ('MG 2', 'MA 1' ,'MS 2')").CopyToDataTable()
To get the total count
Dt.Select("ColumnName in ('MG 2', 'MA 1' ,'MS 2')").Length

Regards,
Arivu

the dictionary approach:

dictCValCount | Dictionary(Of String, Int32) =

(From d in dtData.asEnumerable
Group d by k=d(“C”).toString.Trim into grp=Group
Select t= Tuple.Create(k, grp.Count)).ToDictionary(Function (x) x.Item1, Function (x) x.Item2)

With a prepared datatable, having 2 cols, Key, Count - dtStatistic we can do:

dtStatistic =
(From d in dtData.asEnumerable
Group d by k=d(“C”).toString.Trim into grp=Group
Let ra = new Object(){k, grp.Count}
Select r= dtStatistic.Rows.Add(ra)).CopyToDataTable

you will get back a datatable with the statistical info

@ppr

I can’t test the second structure

you missed out to prepare the dtStatistic datatable in advance


grafik

Find starter help here:
texte linq_V2.xaml (9.9 KB)

2 Likes

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