I have a list of codes in an excel data table. In UIPath, I would like to count the occurances of for each code. For example if I have the below list, I would like the output to show me that there are 2 N1s, 1 N2, and 1 N3. I would also like to show 0 for codes that are not present, such as N4. Is this possible in UIPath, and if so what is the best way to go about it? Thanks!
1.) Create a new datatable without distinct values with the Remove Duplicates activity.
2.) Iterate over your new table and for each value in the table, get the count using DtOriginal.Select("[ColumnName] = '" + row(0).ToString + "').Count, where DtOriginal is your original datatable, ColumnName is the name of the column from your original table, and row is the row from your distinct datatable you created in step 1.
@amanda.b.derdiger
As an alternate
Create a new var dtResult of datatype Datatable
Use an assign and implement
dtResult =Yourorigindatatablevar.Clone
Add a new column with the Name e.g Count to dtResult
Now within assign
Legt Side: dtResult
Right Side:
(From d in yourorigindatatablevar.asenumerable
group d by k=d(0).toString.trim into grp=Group
Let ra = {k, grp.count}
Select dtResult.Rows.Add(ra)).CopyToDataTable
Thank you for this. I tried to write the code for the right side of the assign function, but I am getting the following error. Do you know what might be causing it?
Additionally the next step of this will be to use if functions to write out certain text depending on which codes are present and their count. Will this solution allow for that?
Here is an example of my input file. Essentially I need to count the number of occurance of each code. Then, I need to create a variable so that for example if there are instances of N11, I can type out something like “There are 3 instances of N11”
I was able to find the solution in another post. I created variables for the Count of each code and used an assign activity with the following on the right: