# Compare 2 excel sheets using uipath

**URL:** <https://forum.uipath.com/t/compare-2-excel-sheets-using-uipath/472188>\
**Category:** Activities\
**Tags:** datatable, excel, activities\
**Created:** [September 12, 2022, 5:38am UTC](https://forum.uipath.com/t/compare-2-excel-sheets-using-uipath/472188 "2022-09-12T05:38:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![alamelu.b](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/alamelu.b/32/263147_2.png) [@alamelu.b](https://forum.uipath.com/u/alamelu.b)\
**Post date:** [September 12, 2022, 5:38am UTC](https://forum.uipath.com/t/compare-2-excel-sheets-using-uipath/472188/1 "2022-09-12T05:38:49Z")

</div>

I want to compare two columns of two different Excel sheets and return the corresponding 3rd column value of 2nd excel sheet infront of corresponding matched rows of 1st excel sheet.

Suppose Excel 1 contains follow value

```auto
Sl.No Count
-------------------------------
105 1  
106 2  
107 3  
108 4  
109 5  
110 6  

```

Excel 2 contain

```auto
Sl.No Count Grade
-----------------------
108 4 A  
109 5 B  
110 6 C  
111 1 D  

```

Expected result

```auto
Sl.No Count Grade
-------------------------
105 1  
106 2 
107 3 
108 4 A  
109 5 B  
110 6 C  

```

Please suggest, what function should I use. by using UiPath?

---

<div class="post-metadata">

**Author:** ![Sanjit\_Pal](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sanjit_pal/32/193785_2.png) [@Sanjit\_Pal](https://forum.uipath.com/u/Sanjit_Pal)\
**Post date:** [September 12, 2022, 5:48am UTC](https://forum.uipath.com/t/compare-2-excel-sheets-using-uipath/472188/2 "2022-09-12T05:48:01Z")

</div>

Hey @alamelu.b,

Have a look on this thread.

> [@How to compare two excel sheet & update the matched value in sheet 2](https://forum.uipath.com/t/how-to-compare-two-excel-sheet-update-the-matched-value-in-sheet-2/331078):
>
> Hi all, I have 2 worksheets, In sheet 1 it holds ID & Amount and in sheet 2 it has only ID. I have to compare both sheet & If Id matched I want to get the amount and write in sheet 2, example, Worksheet A ID Amount 1111 $123 2222 $678 3333 $980 4444 $650 Worksheet B ID Amount 1111 $123 5555 3333 $980 0444 Thanks in advance

Thanks,  
Sanjit

---

<div class="post-metadata">

**Author:** ![Gokul001](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gokul001/32/462734_2.png) [@Gokul001](https://forum.uipath.com/u/Gokul001)\
**Post date:** [September 12, 2022, 6:17am UTC](https://forum.uipath.com/t/compare-2-excel-sheets-using-uipath/472188/3 "2022-09-12T06:17:16Z")

</div>

Hi @alamelu.b

Welcome to Uipath Community

You can try with **Lookup DataTable** activity

Check out the **Documentation**

> **[Lookup Data Table](https://docs.uipath.com/activities/docs/lookup-data-table)**
>
> UiPath.Core.Activities.LookupDataTable This activity enables you to search for a provided value in a specified DataTable and returns the RowIndex at which it was found. If the provided value is not found, then the returned RowIndex is -1. This...

Here is the **Workflow**

 ![image](https://global.discourse-cdn.com/uipath/original/4X/0/e/4/0e446b5e88e2dc9e88c40e59ff3d499aebaa27d0.png)

[ExcelCompare.xaml](https://forum.uipath.com/uploads/short-url/s5kpy4wbYcqK9w1N319c7QSLthg.xaml) (17.0 KB)

**Output**

![image](https://global.discourse-cdn.com/uipath/original/4X/7/c/e/7ce8fd92fa59ce808ef33640edc6fc7a0a1e40ed.png)

Regards  
Gokul

---

<div class="post-metadata">

**Author:** ![alamelu.b](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/alamelu.b/32/263147_2.png) [@alamelu.b](https://forum.uipath.com/u/alamelu.b)\
**Post date:** [September 12, 2022, 6:21am UTC](https://forum.uipath.com/t/compare-2-excel-sheets-using-uipath/472188/4 "2022-09-12T06:21:17Z")

</div>

thank you for your respnse but i used linq only not for each

---

<div class="post-metadata">

**Author:** ![raja.arslankhan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/raja.arslankhan/32/463418_2.png) [@raja.arslankhan](https://forum.uipath.com/u/raja.arslankhan)\
**Post date:** [September 12, 2022, 7:18am UTC](https://forum.uipath.com/t/compare-2-excel-sheets-using-uipath/472188/5 "2022-09-12T07:18:28Z")

</div>

Hi @alamelu.b,  
DT1.AsEnumerable().Where(Function(row) DT2.AsEnumerable().Where(function(r) r(“ColName”).ToString.Equals(row(“ColName”).ToString).Any).ToArray

please try This One

---

<div class="post-metadata">

**Author:** ![rohith.prabhu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/rohith.prabhu/32/159488_2.png) [@rohith.prabhu](https://forum.uipath.com/u/rohith.prabhu)\
**Post date:** [September 12, 2022, 7:26am UTC](https://forum.uipath.com/t/compare-2-excel-sheets-using-uipath/472188/6 "2022-09-12T07:26:44Z")

</div>

Hello @alamelu.b ,

You can use the below Linq to achieve this :

Use assign activity and assign  
outDT = TestDt2.Clone()

Assign :

> outDT = (From R1 In TestDt1.AsEnumerable  
> From R2 In TestDt2.AsEnumerable  
> Where ((R1.Item(“SI.No”).ToString.Trim.Equals(R2.Item(“SI.No”).ToString.Trim) AndAlso (R1.Item(“Count”).ToString.Trim.Equals(R2.Item(“Count”).ToString.Trim))  
> Select R = outDT.Rows.Add((R1.ItemArray.Append(R2.Item(“Grade”).ToString).ToArray))).CopyToDataTable()

Please let us know if you face any challenges in implementation.

Regards,  
Rohith

---

<div class="post-metadata">

**Author:** ![alamelu.b](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/alamelu.b/32/263147_2.png) [@alamelu.b](https://forum.uipath.com/u/alamelu.b)\
**Post date:** [September 12, 2022, 7:28am UTC](https://forum.uipath.com/t/compare-2-excel-sheets-using-uipath/472188/7 "2022-09-12T07:28:50Z")

</div>

thank you for your response

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [September 12, 2022, 8:23am UTC](https://forum.uipath.com/t/compare-2-excel-sheets-using-uipath/472188/8 "2022-09-12T08:23:46Z")

</div>

@alamelu.b  
Your case can be matched to different approaches

**Left Join** (with the assumption on no duplicated S1.No values in dt 1

Assign activity  
dtResult = Dt2.Clone

Assign activity:  
dtResult =

```auto
(From d1 In dt1.AsEnumerable()
Group Join d2 In dt2.AsEnumerable()
On d1("S1.No").toString.Trim Equals d2("S1.No").toString.Trim Into gj= Group
From g In gj.DefaultIfEmpty
Let grd= If(isNothing(g), Nothing, g("Grade"))
Let ra = d1.ItemArray.Append(grd).toArray
Select r = dtResult.Rows.Add(ra)).CopyToDataTable

```

**Match-Lookup**  
Assign activity  
dtResult = Dt2.Clone

Assign activity:  
dtResult =

```auto
(From d1 in dt1.AsEnumerable()
Let sno = d1("S1.No").toString.Trim
Let mtc= dt2.AsEnumerable.Where(Function (d2) d2("S1.No").toString.Trim.Equals(sno)).toList
Let grd = mtc.Select(Function (g) g("Grade")).DefaultIfEmpty(nothing).First()
Let ra = d1.ItemArray.Append(grd).toArray
Select r = dtResult.Rows.Add(ra)).CopyToDataTable

```

@kumar.varun2 thanks for review

---

<div class="post-metadata">

**Author:** ![alamelu.b](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/alamelu.b/32/263147_2.png) [@alamelu.b](https://forum.uipath.com/u/alamelu.b)\
**Post date:** [September 12, 2022, 10:15am UTC](https://forum.uipath.com/t/compare-2-excel-sheets-using-uipath/472188/9 "2022-09-12T10:15:26Z")

</div>

hi, i got ")"end of exception error

---

<div class="post-metadata">

**Author:** ![rohith.prabhu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/rohith.prabhu/32/159488_2.png) [@rohith.prabhu](https://forum.uipath.com/u/rohith.prabhu)\
**Post date:** [September 12, 2022, 10:17am UTC](https://forum.uipath.com/t/compare-2-excel-sheets-using-uipath/472188/10 "2022-09-12T10:17:50Z")

</div>

Hello,

Probably a ‘)’ is missing. I have corrected expression, please use the below :

> (From R1 In TestDt.AsEnumerable  
> From R2 In TestDt2.AsEnumerable  
> Where ((R1.Item(“SI.No”).ToString.Trim.Equals(R2.Item(“SI.No”).ToString.Trim)) AndAlso R1.Item(“Count”).ToString.Trim.Equals(R2.Item(“Count”).ToString.Trim))  
> Select R = NewDt.Rows.Add((R1.ItemArray.Append(R2.Item(“Grade”).ToString).ToArray))).CopyToDataTable()
