Trying to count loop over DataTable rows with a particular value in one column and count unique values in another

833 views Asked by At

I'm developing a workflow in UIPath. I have a DataTable called Matches that I've ported into an Invoke Code block.

Matches is a series of information about Emails and there attachments. Each email and attachment has it's own row in the table with a unique ID number. Each attachment has a RelatesTo column that has the ID number of the email it belongs to.

I've gone and applied a bunch of classification rules to lines to try and sort them into categories. These are recorded in a "RulesID" column. I want to count the number of unique RulesID for each particular RelatesTo value.

I've a hunch that the solution could be fairly simple, but it's been escaping me. Any help would be appreciated

1

There are 1 answers

0
SSS On

The following will give you a new table containing unique combinations of RelatedTo and RulesID. From there you can use a For...Next loop to count the rows.

Dim matches As New DataTable("matches")
matches.Columns.Add("ID")
matches.Columns.Add("RelatesTo")
matches.Columns.Add("RulesID")
matches.Rows.Add("ID10", "ID1", "Rule1")
matches.Rows.Add("ID11", "ID1", "Rule1")
matches.Rows.Add("ID12", "ID1", "Rule2")
matches.Rows.Add("ID13", "ID1", "Rule3")
matches.Rows.Add("ID14", "ID2", "Rule1")
matches.Rows.Add("ID15", "ID2", "Rule3")
matches.Rows.Add("ID16", "ID3", "Rule2")
matches.Rows.Add("ID17", "ID3", "Rule3")
matches.Rows.Add("ID18", "ID4", "Rule3")

Dim unique As DataTable = matches.DefaultView.ToTable("unique", True, New String() {"RelatesTo", "RulesID"})