# Get distinct rows from Datatable from Multiple columns

**URL:** <https://forum.uipath.com/t/get-distinct-rows-from-datatable-from-multiple-columns/101920>\
**Category:** Help\
**Tags:** studio, system, activities\
**Created:** [March 13, 2019, 6:43am UTC](https://forum.uipath.com/t/get-distinct-rows-from-datatable-from-multiple-columns/101920 "2019-03-13T06:43:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajinkya2704](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@ajinkya2704](https://forum.uipath.com/u/ajinkya2704)\
**Post date:** [March 13, 2019, 6:43am UTC](https://forum.uipath.com/t/get-distinct-rows-from-datatable-from-multiple-columns/101920/1 "2019-03-13T06:43:03Z")

</div>

Hi,  
I want to compare two datatables and get distinct values based on multiple columns. Suppose i have dt1 with following data  
|Trailer\_No|Creation\_Date|Ship\_To|Status|  
|RPA\_1|03/01/2019 00:00:00|ABC|Failed|  
|YU87687|01/09/2019 00:00:00|ABC|Failed|  
|987|10/25/2018 00:00:00|ABC|Failed|

and second dt2 with following data  
|Trailer\_No|Creation\_Date|Ship\_To|Status|  
|RPA\_1|03/01/2019 00:00:00|ABC|In Process|  
|YU87687|01/09/2019 00:00:00|ABC|In Process|  
|987|10/25/2018 00:00:00|ABC|In Process|  
|TEST25|07/25/2018 00:00:00|ABC|In Process|  
|TEST25\_1|07/25/2018 00:00:00|ABC|In Process|

now the first three rows in dt2 are duplicate only the status is different. I want those three rows removed and get rows from dt1 with ‘failed’ status and new rows from dt2 into dt3,

Any help is appreciated. TIA

---

<div class="post-metadata">

**Author:** ![HareeshMR](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/hareeshmr/32/181825_2.png) [@HareeshMR](https://forum.uipath.com/u/HareeshMR)\
**Post date:** [March 13, 2019, 6:52am UTC](https://forum.uipath.com/t/get-distinct-rows-from-datatable-from-multiple-columns/101920/3 "2019-03-13T06:52:51Z")

</div>

Try Implementing the steps

1. Read both the excels and store in two data tables.
2. As you want all the values from first table, write first table to a new excel
3. Use for each row to iterate through the rows of second column Trailer\_No and use another for each row inside to compare with the first table Trailer\_No.
4. Use if condition to check whether the values are matched or not ( whatever conditions you want)
5. In **then** condition, use write cell activity to write in the third excel if the values matched or vice-versa.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![ajinkya2704](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@ajinkya2704](https://forum.uipath.com/u/ajinkya2704)\
**Post date:** [March 13, 2019, 7:01am UTC](https://forum.uipath.com/t/get-distinct-rows-from-datatable-from-multiple-columns/101920/4 "2019-03-13T07:01:33Z")

</div>

Hi, I will try your steps and update you. Thanks for the reply

---

<div class="post-metadata">

**Author:** ![Pradeep](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/pradeep/32/51753_2.png) [@Pradeep](https://forum.uipath.com/u/Pradeep)\
**Post date:** [March 13, 2019, 8:12am UTC](https://forum.uipath.com/t/get-distinct-rows-from-datatable-from-multiple-columns/101920/5 "2019-03-13T08:12:47Z")

</div>

@ajinkya2704  
If it is possible just try the code like this,

Create two datatable and assign the above mentioned values and using assign activity

dtTest3 = (From x In ((From y In dtTest1.AsEnumerable() Select y).Union(From z In  
dtTest2.AsEnumerable() Select z))  
Group By Y = New With { Key.Id=x(“ID”), Key.Name=x(“Name”)} Into GroupA= Group  
Select GroupA(0)).Toarray().copytodatatable()

Thanks,  
Pradeep Sridharan

---

<div class="post-metadata">

**Author:** ![ajinkya2704](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@ajinkya2704](https://forum.uipath.com/u/ajinkya2704)\
**Post date:** [March 13, 2019, 9:47am UTC](https://forum.uipath.com/t/get-distinct-rows-from-datatable-from-multiple-columns/101920/6 "2019-03-13T09:47:56Z")

</div>

@Pradeep thanks for the reply, let me explain what i am currently doing, I am merging the two datatable into a third one, then i am doing Datatable.DefaultView.ToTable(True,“Trailer\_No”,“Creation\_Date”,“Ship\_To”,“Status”)  
This is also not removing duplicates, am i doing anything wrong here!

Thanks,  
AJ

---

<div class="post-metadata">

**Author:** ![Pradeep](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/pradeep/32/51753_2.png) [@Pradeep](https://forum.uipath.com/u/Pradeep)\
**Post date:** [March 13, 2019, 11:15am UTC](https://forum.uipath.com/t/get-distinct-rows-from-datatable-from-multiple-columns/101920/7 "2019-03-13T11:15:49Z")

</div>

@ajinkya2704

Please find the below xaml

[Main.xaml](https://global.discourse-cdn.com/uipath/original/3X/8/b/8b1960fe4538fd6ab9ac96d3d41059a73dece7bd.xaml) (18.8 KB)

Thanks,

Pradeep Sridharan

---

<div class="post-metadata">

**Author:** ![ajinkya2704](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@ajinkya2704](https://forum.uipath.com/u/ajinkya2704)\
**Post date:** [March 13, 2019, 12:52pm UTC](https://forum.uipath.com/t/get-distinct-rows-from-datatable-from-multiple-columns/101920/8 "2019-03-13T12:52:00Z")

</div>

@Pradeep I tested your code and integrated in my workflow, it working as expected, appreciate your help 🙂

Thanks,  
AJ

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [March 16, 2019, 12:52pm UTC](https://forum.uipath.com/t/get-distinct-rows-from-datatable-from-multiple-columns/101920/9 "2019-03-16T12:52:02Z")

</div>

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