Count how many pair of unique values in data table

Hi I am trying to count how many unique pairs in a data table with 2 columns, how will that be done?

@Petrifly If a datatable say DT has duplicate rows, you can get the Unique rows by using DT.DefaultView.ToTable(True) and if you want to know the count of the rows, you can just use this expression :


Does this apply for pair of unique values? First value from column 1 and second value from column 2.

@Petrifly Unique Row Pairs of the datatable will be the output of the above Expression which I have provided, if you need a different solution please explain in detail with some examples as to what is the Input and what is the output that you expect.

I see, understood. How about for cases where there are multiple columns but I only want to check if two specific columns have a unique row pair? Is there an expression that can check this or will I have to extract the two columns I want and create a separate data table to use DT.DefaultView.ToTable(True).Rows.Count.
Ex. 7 columns in a table but I want the first and fourth columns.

@Petrifly Yes. I think you can do it.

DT.DefaultView.ToTable(True,“First Column Name”,“Fourth Column Name”).Rows.Count

This will get the unique pair rows count for the First two Columns in the Datatable. Can you try and check if it is the output you need.


Thanks for the help, will try it.

1 Like