Hi
I have a sequence where have a counter variable declared =0
success = 0
failure = 0
my flow ->Try block (read range → for each → then 2 if conditions) catch block empty
i have two if conditions : one to check string = success in the current row of a dtTable coming
if it finds success then my counter = success +1
another if does same thing for string = failure in the current row of a dtTable coming
if it finds failurethen my counter = failure +1
but i have more then 1lakh rows
i want the final counter of answers to be stored and sent to my client !!
for example: success items= 29 and fail items = 9
but what happens when the column has no value for more then 70thousand lines and the log message keeps on prinitingthe counter values for them
can someone guide me what is the efficient way here ?
@samantha_shah
place the second if activity in the else block of first if activity so that it if it is not success, it will check for the failure one.
PaviS
(Pavithra S)
March 6, 2024, 5:29am
3
@samantha_shah
Hope you need to take the Success and Failure count from the column “Status” in a data table. If so please check the following 2 approaches. You can go either of it.
Use 2 filter data table activity. One for success and other for failure. From the filtered data table u can get the rows count using —> dtname.rows.count.tostring
You can use the assign variable name= DTname.Select(“Status = ‘Success’”).Length.ToString and the same way for failure status.
Let me know if you need any clarification.
mkankatala
(Mahesh Kankatala)
March 6, 2024, 5:30am
4
Hi @samantha_shah
Your data is in the datatable, success and failure is in the column and you want to get the Count of Status rows and Failure rows.
If this is your case, then you can use the LINQ expressions to get the Count and store in a Variables.
- Assign -> Success_Count = dt.AsEnumerable().Count(Function(X) X("Column name").Equals("Success"))
- Assign -> Failure_Count = dt.AsEnumerable().Count(Function(X) X("Column name").Equals("Failure"))
Note : Success_Count and Failure_Count are the Int32 datatype variables and change the column name in the both LINQ Expressions.
Hope it helps!!
1 Like
Yoichi
(Yoichi)
March 6, 2024, 5:31am
5
Hi,
If you want to count number of rows which has “Success”, the following will work.
dt.AsEnumerable.Count(Function(r) r("Status").ToString()="Success")
Or if you need to do some process in the loop, dictionary will help you as the following.
dict = New Dictionary(Of String,Int32)From {{"Success",0},{"Failure",0}}
Then
dict(CurrentRow("Status").ToString()) = dict(CurrentRow("Status").ToString()) +1
dict(“Success”) and dict(“Failure”) will return sum value for each item.
note: It’s unnecessary to use IF
Regards,
1 Like
devik
(Devi Kandasamy)
March 6, 2024, 5:32am
6
Hi @samantha_shah . Use 2 Filter datatable activities with success and Failure condition match and then get rowcount of each table. Activities - Filter Data Table
1 Like
Hi @PaviS
i am trying to learn this activity filter data table
took two activities
can you please tel me how can i get the column name here ? and what alterations will i require in the activity to give me the following output you mentiones
please let me know , ican read somewhere as well if you are busy and i can learn this
thanks
mkankatala
(Mahesh Kankatala)
March 6, 2024, 6:02am
9
Instead of doing all this, use the LINQ Expressions which is simpler and you can directly use those in assign activity, check the above response,
Hi @samantha_shah
Your data is in the datatable, success and failure is in the column and you want to get the Count of Status rows and Failure rows.
If this is your case, then you can use the LINQ expressions to get the Count and store in a Variables.
- Assign -> Success_Count = dt.AsEnumerable().Count(Function(X) X("Column name").Equals("Success"))
- Assign -> Failure_Count = dt.AsEnumerable().Count(Function(X) X("Column name").Equals("Failure"))
Note : Success_Count and Failure_Count are …
If you need any further assistance needed let me know… @samantha_shah
Hi @samantha_shah
At last in DT you can use Linq for it to get the count
DT.AsEnumerable.Count(Function(x) x("Status").ToString.Equals("Success"))
DT.AsEnumerable.Count(Function(x) x("Status").ToString.Equals("Failure"))
Hope it will helps you
Cheers!!
Hi @mkankatala
thanks for further ideas
the reason i didnt too LINQ expressin because i had no clue what it is
for example: what is function(X)and how does it work
please help me understand it will be helpful
mkankatala
(Mahesh Kankatala)
March 6, 2024, 6:13am
12
Okay @samantha_shah
You can simply use the LINQ Expression in assign activity.
dt.AsEnumerable()
: This converts the DataTable dt
into an enumerable collection of DataRow objects. This allows us to use LINQ queries to manipulate and query the data in the DataTable.
.Count()
: This LINQ extension method counts the number of elements in the sequence that satisfies a given condition.
Function(row)
: This is a lambda function that takes a DataRow (row
) as input.
Hope you understand!!
1 Like
thanks for the clarification it helped me
@mkankatala
1 Like
mkankatala
(Mahesh Kankatala)
March 6, 2024, 6:23am
14
It’s my pleasure… @samantha_shah
Happy Automation!!
1 Like
system
(system)
Closed
March 9, 2024, 6:24am
15
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.