How to count amount of times a term appears in rows of a DataTable and return it

Hi,

I would like to know how I can count the amount of times a term appears in the rows of a DataTable. Say f.e.:

  • Ben
  • Stef
  • Ben
  • Rose

How could I make it return saying:

  • Ben: 2
  • Stef: 1
  • Rose: 1

Any help would be appreciated!

Thanks in advance.

lets get returned a dictionary where key is the term and value is count

Assign activity:
dictLKTCount | Dictionary(of String, Int32) =

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

Thanks for your reply!

Could you maybe visualise this in a Sequence? That would be a lot easier to understand!

Thank you

grafik
thats all we need

Just update the variable YourDataTableVar and the ColumnName or Index to your specifics

Thanks for your reply.

It returns “Cannot assign from type System.Collections.Generic.Dictionary2[System.String.System.Int32] to type ‘System.String’ in the Assign activity” however. How do I fix this?

you need to adapt the datatype
grafik

Do you have the full .net type so I can find it? I don’t have it by default and can’t seem to find it in my dependencies

grafik
grafik

Click then OK, OK

1 Like

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