Check if value is > 0 inside a datatable

Hi all,
i want to count how many times a specific value inside a column of datatable appear, and i use this:
CountA = finalDT.Select("[Column 6] = ‘SOSPENSION’ ").CopyToDataTable.Rows.count

My problem is: when i haven’t values for SOSPENSION inside column 6, it go in error with “the source contains no Datarows” but in that case i want to put value 0 in my variable CounA, how can i do that?

Thanks

1 Like

hey
Main.xaml (5.5 KB)
Tried this
is this what you are looking for?New Microsoft Office Excel Worksheet.xlsx (8.1 KB)

1 Like

worked??

1 Like

Thanks for the reply, not really that

My goal is to write into an excel spreadsheet how many times a particular value in the column 6 appear in my datatable.
And i use this expression CountA = finalDT.Select("[Column 6] = ‘SOSPENSION’ ").CopyToDataTable.Rows.count and it work!
The only problem is when the number of SOSPENSION in Column 6 is = 0, because it expect a value > 0

Hi @yiroday,

It is due to the fact that you are trying to convert empty rows to a Data Table. Instead of that you can straightaway get the count like below.

CountA = finalDT.Select("[Column 6] = ‘SOSPENSION’ ").CopyToDataTable.Rows.count

Instead of the above code change it like the following:

CountA = finalDT.Select("[Column 6] = ‘SOSPENSION’").Count
1 Like

I’ve tried with the second expression but i have this warn

“message”: “Assign: Cannot find column [‘SOSPENSION’].”
the expression is
finalDT.Select(“[Column 6] = ‘SOSPENSION’”).Count

Dim artnrGroups = From a In finalDT _
                    Group a By Key = a.SOSPENSION Into Group _
                    Where Group.Count() > 1
                    Select Group.Count()
1 Like

Thanks @bcorrea

i use this expression in an assign activity? i’m not a veteran, can you explain a little bit that please?

yes, create a numeric variable and assign to the expression:

From a In finalDT _
Group a By Key = a.SOSPENSION Into Group _
Where Group.Count() > 1
Select Group.Count()