How to count the number cells in a row ignoring empty cells?

Hi guys,

I will need to count the number of items i have in a row. I did a dt.rows.count.ToString but it counted all the cells in that row including empty cells. Please help.

Considering dt is your datatable variable, “dt.rows.count” will not return all the cells in your rows, but would instead return all the rows in the datatable.

Use this instead:

dr.ItemArray.Length.toString to find the number of items in your row,

where dr is a specific row in your table dt.

~Sid

1 Like

Hi Sid,

There is a error that says ItemArray is not a member of system.data.dataTable

Dear Kai,

It isn’t obviously. You’re using the datatable object instead of a data row object.

Try this:

dt.rows(0).ItemArray.Length.toString

1 Like

Dt.select.where(function(row) row.item(0).tostring.isnullorempty).count
@Kai

If this helps, please mark the response as solution for other users

1 Like

Hi Sid,

The results came back with only 1 where i have 4 items in that row.

Hi tdhaene,

Seems like there are errors in using isnullorempty. Here’s the errors:

Overload resolution failed because no accessible ‘IsNullorEmpty’ is most specific for these arguments;
Extension method ‘public function IsNullOrEmpty() As Boolean’ defined in ‘System.Extensions’: Not most specific

Hello @Kai
try this…

dt.Select().Where(function( r) r(0).ToString.Count > 0).Select(function( r) r).CopyToDataTable.Rows.Count.ToString

above is for first column… change column index you require…

Can you copy paste your value of the assign statement,so i can verify?

Hello @Kai
Please check this workflow once to get an idea.
Sequence.xaml (9.0 KB)

1 Like

Hi @vickydas

In your xaml, what if I want to get the rows with the empty cells instead of getting the rows with values?

Hello @RailCay

We would just have to change the conditions in our query and get the rows which have no value

Check this workflow out for better understanding

DT Rows.xaml (10.6 KB)