# Select method to filter excel sheet

**URL:** <https://forum.uipath.com/t/select-method-to-filter-excel-sheet/378427>\
**Category:** Something Else\
**Tags:** excel, system, activities\
**Created:** [December 19, 2021, 10:34am UTC](https://forum.uipath.com/t/select-method-to-filter-excel-sheet/378427 "2021-12-19T10:34:37Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dmitri00007](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/dmitri00007/32/279009_2.png) [@Dmitri00007](https://forum.uipath.com/u/Dmitri00007)\
**Post date:** [December 19, 2021, 10:34am UTC](https://forum.uipath.com/t/select-method-to-filter-excel-sheet/378427/1 "2021-12-19T10:34:37Z")

</div>

I’m using this method to filter my excel sheet  
(  
From row In out\_excel1\_DataTable  
Group row By a = row(“Column B”).ToString Into grp = Group  
Select grp.First  
).CopyToDataTable

“column B” contains bunch of unique invoice number, suppose (invoice number = 1234, has 50 rows) and every single row has a price column, we just need single row data of single invoice but we need sum of price from the 50 rows.

please help me I’m stuck here

---

<div class="post-metadata">

**Author:** ![Dmitri00007](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/dmitri00007/32/279009_2.png) [@Dmitri00007](https://forum.uipath.com/u/Dmitri00007)\
**Post date:** [December 19, 2021, 11:01am UTC](https://forum.uipath.com/t/select-method-to-filter-excel-sheet/378427/2 "2021-12-19T11:01:48Z")

</div>

take this sample sheet, invoice number is repetitive and we need just one row of one invoice. with sum of incident cost.

one entry on invoice no. (12345) and sum of incident cost L2:L85  
[01.xlsx](https://forum.uipath.com/uploads/short-url/7uSk1wEzrjCTRwB3wJ1Q9mZczFg.xlsx) (100.9 KB)

---

<div class="post-metadata">

**Author:** ![Jobin\_Joy](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jobin_joy/32/555040_2.png) [@Jobin\_Joy](https://forum.uipath.com/u/Jobin_Joy)\
**Post date:** [December 19, 2021, 1:11pm UTC](https://forum.uipath.com/t/select-method-to-filter-excel-sheet/378427/3 "2021-12-19T13:11:16Z")

</div>

Hi @Dmitri00007

Can you try this?

var result = (from row in YourTable  
group row by new {row.InvoiceNumber}  
into grp  
select new  
{  
grp.Key.InvoiceNumber,  
Quantity = grp.Sum(row =\> row.IncidentCost)  
}).ToList();

Thank you.

---

<div class="post-metadata">

**Author:** ![Jobin\_Joy](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jobin_joy/32/555040_2.png) [@Jobin\_Joy](https://forum.uipath.com/u/Jobin_Joy)\
**Post date:** [December 19, 2021, 1:15pm UTC](https://forum.uipath.com/t/select-method-to-filter-excel-sheet/378427/4 "2021-12-19T13:15:50Z")

</div>

Alternately you can try the below one as well,

dtResults = (From dte In dtTable.AsEnumerable  
Group dte By col1=**dte(2)**.ToString.Trim Into Group  
Select dtResults.Rows.Add({col1, Group.Sum(Function (x) CInt(**x(1**).toString.Trim))})).CopyToDataTable

Note: Give the correct index of the column in the highlighted (in Bold) places.

Hope this will help you. Thank you.

---

<div class="post-metadata">

**Author:** ![Dmitri00007](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/dmitri00007/32/279009_2.png) [@Dmitri00007](https://forum.uipath.com/u/Dmitri00007)\
**Post date:** [December 19, 2021, 2:22pm UTC](https://forum.uipath.com/t/select-method-to-filter-excel-sheet/378427/5 "2021-12-19T14:22:49Z")

</div>

![Screenshot (20)](https://global.discourse-cdn.com/uipath/original/4X/1/7/6/176479281a2adbb977e765ca589f619926c62dfa.png)

The Datatabe variable name is out\_excel1\_DataTable  
Column name is Invoice Number  
sum Column name - Spot Net Amount

I’m getting this error

---

<div class="post-metadata">

**Author:** ![Jobin\_Joy](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jobin_joy/32/555040_2.png) [@Jobin\_Joy](https://forum.uipath.com/u/Jobin_Joy)\
**Post date:** [December 19, 2021, 2:28pm UTC](https://forum.uipath.com/t/select-method-to-filter-excel-sheet/378427/6 "2021-12-19T14:28:24Z")

</div>

> [@Jobin\_Joy](#):
>
> dtResults = (From dte In dtTable.AsEnumerable  
> Group dte By col1= **dte(2)**.ToString.Trim Into Group  
> Select dtResults.Rows.Add({col1, Group.Sum(Function (x) CInt( **x(1)**.toString.Trim))})).CopyToDataTable
> 
> Note: Give the correct index of the column in the highlighted (in Bold) places.

@Dmitri00007  
Please try with this.

I can see the syntax error due to incorrect spelling in your above screenshot.

Thank you.

---

<div class="post-metadata">

**Author:** ![Jobin\_Joy](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jobin_joy/32/555040_2.png) [@Jobin\_Joy](https://forum.uipath.com/u/Jobin_Joy)\
**Post date:** [December 19, 2021, 2:46pm UTC](https://forum.uipath.com/t/select-method-to-filter-excel-sheet/378427/7 "2021-12-19T14:46:30Z")

</div>

Hi @Dmitri00007

If you are very new to this, let me know I can share xaml file here.

Thank you.

---

<div class="post-metadata">

**Author:** ![Jobin\_Joy](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jobin_joy/32/555040_2.png) [@Jobin\_Joy](https://forum.uipath.com/u/Jobin_Joy)\
**Post date:** [December 19, 2021, 3:00pm UTC](https://forum.uipath.com/t/select-method-to-filter-excel-sheet/378427/8 "2021-12-19T15:00:53Z")

</div>

Hi @Dmitri00007

Here is the code for your requirement,

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

I have added a new sheet (Result) in the same excel file store the result. If need, you can store it in a separate excel file as well.

**Result:**

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

**Code:**  
[GroupBy.xaml](https://forum.uipath.com/uploads/short-url/fJ9t9SgE2BQMApyDW4jrZRqSXYT.xaml) (7.9 KB)

Kindly mark this post as solution, if this one is helped you.

Thank you.

---

<div class="post-metadata">

**Author:** ![Dmitri00007](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/dmitri00007/32/279009_2.png) [@Dmitri00007](https://forum.uipath.com/u/Dmitri00007)\
**Post date:** [December 19, 2021, 3:24pm UTC](https://forum.uipath.com/t/select-method-to-filter-excel-sheet/378427/9 "2021-12-19T15:24:24Z")

</div>

Thanks for your help. I’m able to filter it.  
Yes, this is my first month of learning.

---

<div class="post-metadata">

**Author:** ![Jobin\_Joy](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jobin_joy/32/555040_2.png) [@Jobin\_Joy](https://forum.uipath.com/u/Jobin_Joy)\
**Post date:** [December 19, 2021, 3:28pm UTC](https://forum.uipath.com/t/select-method-to-filter-excel-sheet/378427/11 "2021-12-19T15:28:10Z")

</div>

Hi @Raj\_Ayush\_Gupta

So glad to hear that this is your first learning and the code is working fine now.

Please mark my above post as ‘Solution’ so that it will be helpful for others as well.

Thank you.

---

<div class="post-metadata">

**Author:** ![Dmitri00007](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/dmitri00007/32/279009_2.png) [@Dmitri00007](https://forum.uipath.com/u/Dmitri00007)\
**Post date:** [December 19, 2021, 3:39pm UTC](https://forum.uipath.com/t/select-method-to-filter-excel-sheet/378427/12 "2021-12-19T15:39:31Z")

</div>

Marked, thank you so much.

I need one more help, just a question.  
Can we use whildcard in string value {Assign Activity}

“C:\Users\Downloads\excel/” + today.ToString(“MMMMyyyy”)+“/SpotsReport\_”+Today.Tostring(“dd\_MM\_yyyy\_”)+“ **4567865**.zip”

4567865 replace this value with whildcard.

Using Assign Activity

---

<div class="post-metadata">

**Author:** ![Jobin\_Joy](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jobin_joy/32/555040_2.png) [@Jobin\_Joy](https://forum.uipath.com/u/Jobin_Joy)\
**Post date:** [December 19, 2021, 3:47pm UTC](https://forum.uipath.com/t/select-method-to-filter-excel-sheet/378427/13 "2021-12-19T15:47:09Z")

</div>

Hi @Dmitri00007

Please create new Topic for this question. So that it will be easy to isolate topics.

Just copy paste and create a new one.

Thank you.

---

<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:** [December 22, 2021, 3:47pm UTC](https://forum.uipath.com/t/select-method-to-filter-excel-sheet/378427/14 "2021-12-22T15:47:12Z")

</div>

Closed on December 22, 2021, 3:47pm UTC

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