# Remove rows with no data from datatable

**URL:** <https://forum.uipath.com/t/remove-rows-with-no-data-from-datatable/761982>\
**Category:** Studio\
**Tags:** object-repository, question, studio, system, activities\
**Created:** [August 23, 2024, 6:02pm UTC](https://forum.uipath.com/t/remove-rows-with-no-data-from-datatable/761982 "2024-08-23T18:02:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![FrankWilson](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/frankwilson/32/400705_2.png) [@FrankWilson](https://forum.uipath.com/u/FrankWilson)\
**Post date:** [August 23, 2024, 6:02pm UTC](https://forum.uipath.com/t/remove-rows-with-no-data-from-datatable/761982/1 "2024-08-23T18:02:00Z")

</div>

Hello,

I am looping through data and populating a datatable.  
However, before writing to Excel, would like to remove rows that have no matches.

 ![image](https://global.discourse-cdn.com/uipath/original/4X/9/9/4/994fc43c552b58914201fa7783886010ce99bb18.png)  
In example above, grape and pear would be removed, as they had no matches.  
How can i do this?  
Regards

---

<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:** [August 23, 2024, 6:12pm UTC](https://forum.uipath.com/t/remove-rows-with-no-data-from-datatable/761982/2 "2024-08-23T18:12:37Z")

</div>

We can do:

Assign Activity  
dtCleansed =

```auto
(From d in YourDataTableVar.AsEnumerable
Let chk = d.ItemArray.Skip(1).All(Function (x) isNothing(x) OrElse String.IsNullorEmpty(x.toString.Trim))
Where not chk
Select r = d).CopyToDataTable

```

Handling emtpy results we do:

> [@ambulance sos \[FirstAid\] Handling of The source contains no DataRows exception](https://forum.uipath.com/t/firstaid-handling-of-the-source-contains-no-datarows-exception/410526):
>
> This FirstAid Tutorial will describe how a the source contains no DataRows EXCEPTION can be handled. Introduction Let’s have a look at the following filter data table scenario: Name CCode Tom US Charlotte FR Seema IN Jean FR Assignment: Filter all rows on a particular Country Code like FR, UK, ES, UK… Ensure that all CCode data column values are trimmed Ensure that the Filter check is case insensitive we can implement it e.g. with the help of a LINQ statement: dtData.AsE…

---

<div class="post-metadata">

**Author:** ![FrankWilson](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/frankwilson/32/400705_2.png) [@FrankWilson](https://forum.uipath.com/u/FrankWilson)\
**Post date:** [August 23, 2024, 6:28pm UTC](https://forum.uipath.com/t/remove-rows-with-no-data-from-datatable/761982/3 "2024-08-23T18:28:28Z")

</div>

Thank you so much.  
Tested and works great.  
Greatly reduces output.  
Appreciate the help.

---

<div class="post-metadata">

**Author:** ![FrankWilson](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/frankwilson/32/400705_2.png) [@FrankWilson](https://forum.uipath.com/u/FrankWilson)\
**Post date:** [August 23, 2024, 6:44pm UTC](https://forum.uipath.com/t/remove-rows-with-no-data-from-datatable/761982/4 "2024-08-23T18:44:33Z")

</div>

Hi PPR,

Similar question. Will it be a new search to remove the empty columns as well.  
Like Thursday had no match.  
Regards,

---

<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:** [August 23, 2024, 6:49pm UTC](https://forum.uipath.com/t/remove-rows-with-no-data-from-datatable/761982/5 "2024-08-23T18:49:36Z")

</div>

> [@\[HowTo\] LINQ (VB.Net) Learning Catalogue](https://forum.uipath.com/t/howto-linq-vb-net-learning-catalogue/325671):
>
> This topic references the different Learning HowTos related to LINQ. It will be updated on new published HowTos as well LINQ Learning: Topic LINK First Start with LINQ [[HowTo] - First Start with LINQ (VB.Net)](https://forum.uipath.com/t/howto-first-start-with-linq-vb-net/318964/) Exploring the LINQ universe [[HowTo] - Exploring the LINQ Universe (VB.Net)](https://forum.uipath.com/t/howto-exploring-the-linq-universe-vb-net/325667)Operator [HowTo] Overview Topic LINK Where [[HowTo] LINQ - First Start # Where Operator](https://forum.uipath.com/t/howto-linq-first-start-where-operator/464108) Select work in progress Any [[HowTo] LINQ – First Start # Any Operator](https://forum.uipath.com/t/howto-linq-first-start-any-operator/466138) All [[HowTo] LINQ – First Start…](https://forum.uipath.com/t/howto-linq-first-start-all-operator/467292)

removing rows where any col is a blank:

```auto
(From d in YourDataTableVar.AsEnumerable
Let chk = d.ItemArray.Skip(1).Any(Function (x) isNothing(x) OrElse String.IsNullorEmpty(x.toString.Trim))
Where not chk
Select r = d).CopyToDataTable

```

---

<div class="post-metadata">

**Author:** ![FrankWilson](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/frankwilson/32/400705_2.png) [@FrankWilson](https://forum.uipath.com/u/FrankWilson)\
**Post date:** [August 23, 2024, 6:55pm UTC](https://forum.uipath.com/t/remove-rows-with-no-data-from-datatable/761982/6 "2024-08-23T18:55:05Z")

</div>

That is the same formula.  
Sorry for not being clearer.  
Is it possible to remove columns as well that have no matching data?  
Like Thursday above?  
Regards

---

<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:** [August 23, 2024, 6:57pm UTC](https://forum.uipath.com/t/remove-rows-with-no-data-from-datatable/761982/7 "2024-08-23T18:57:58Z")

</div>

> [@FrankWilson](#):
>
> That is the same formula.

No is not the same on one we are using All on the other we are using Any.

We recommend to use the reference information and have a closer look on LINQ and its operators

---

<div class="post-metadata">

**Author:** ![FrankWilson](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/frankwilson/32/400705_2.png) [@FrankWilson](https://forum.uipath.com/u/FrankWilson)\
**Post date:** [August 23, 2024, 7:15pm UTC](https://forum.uipath.com/t/remove-rows-with-no-data-from-datatable/761982/8 "2024-08-23T19:15:42Z")

</div>

Thank you. The remove rows worked well. However, removing empty columns results in “value cannot be null” error.

---

<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:** [August 23, 2024, 7:24pm UTC](https://forum.uipath.com/t/remove-rows-with-no-data-from-datatable/761982/9 "2024-08-23T19:24:16Z")

</div>

we prefer to have scoped 1 topic = 1 use case  
just open a new topic for your second question and share with us

- sample input example data
- expected output sample  
Thanks

---

<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:** [August 26, 2024, 7:24pm UTC](https://forum.uipath.com/t/remove-rows-with-no-data-from-datatable/761982/10 "2024-08-26T19:24:27Z")

</div>

Closed on August 26, 2024, 7:24pm UTC

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