Combine values under same category

Is there any way, like catogorizing similar data into respective groups? I am confused on how to do this with the for each loop?

Col1
Apple
Banana
Apple
Mango
Pineapple
Mango

Then I need Col2

2
1
2
1

Hi @Praj01, welcome to the Community.

Assuming the you are taking the count of the items from Col1 & writing it in the Col2, you can simply use the grouping query to achieve this. Please refer to the following resource & let us know:

Hope this helps,
Best Regards.

Hi,

How about the following?

dict = dt.AsEnumerable.GroupBy(Function(r) r(0).toString).ToDictionary(Function(g) g.Key,Function(g) g.Count)

Sample20230629-4L.zip (8.5 KB)

Regards,

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