How can I count elements of one excel column?
In this case, for example, I have to count elements of column R
Hey!
If you wants to get the count of the rows try like this
TestDt.AsEnumerable().Select(Function(x) x.Field(Of String)(“YourColumnName”).Trim).ToArray().Where(Function(y) Not String.IsNullOrEmpty(y)).ToArray().Count
Regards,
NaNi
you could use a for each with the data table and use a count, so when each cell does not equal string.empty you increment the count
use this select query DataTable.Select(“‘YourcolumnName’ <> ‘’”).Count.ToString
we assume that the excel is read ranged into a datable
Scenario: Count till the first empty line
Assign Activity
myCount =
dtData.AsEnumerable.TakeWhile(Function (x) Not ( isNothing(x(ColIDXOrName)) OrElse String.IsNullOrEmpty(x(ColIDXOrName).toString.Trim)) ).Count
Scenario: Count all Non Blanks (but maybe reduce by 1 for the Sum Line
Assign Activity
myCount =
dtData.AsEnumerable.Where(Function (x) Not ( isNothing(x(0)) OrElse String.IsNullOrEmpty(x(0).toString.Trim)) ).Count
Find starter help here:
GetCount_NonBlanks.xaml (7.4 KB)
If I know that my column is “S”, without exact name, how can I use it instead “YourColumnName” variable?
If I use “S”, I’m geting “Assign: Column ‘S’ does not belong to table DataTable.”
Hey!
Use Column index instead of columnName
Column index will starts from 0
Your expression is like:
TestDt.AsEnumerable().Select(Function(x) x.Field(Of Double)(19).Trim).ToArray().Where(Function(y) Not String.IsNullOrEmpty(y)).ToArray().Count
Regards,
NaNi
Ok, I tried, but when trying to write result, I am getting this error
I just tried to use it inside Write line activity
(plasiraniJanuar.AsEnumerable().Select(Function(x) x.Field(Of String)(19).Trim).ToArray().Where(Function(y) Not String.IsNullOrEmpty(y)).ToArray().Count).ToString
Hey!
I made the changes in above expression…
Could you please try the mentioned expression now
Regards,
NaNi
What can I use instead of “Your column name”?
I don’t have column name, just index…
Pass index instead of column Name