Finding the index from a Datatable based on multiple conditions

Hi Friends,

I am working on a SAP Automation.
Where I have got a Table.
Now that table I am extracting using Table Extraction and getting the result in Datatable Variable.

now my problem statement is that I want to find the index of row based on different condition .

For Example

image

from the above Screenshot.
I will be knowing that Product category will be LANDSCAPING and Brand will be FISKARS.
how will I find the index of this particular row.
Note: that Columns can increase so I will have to include more conditions .

Please Help.

Thanks In Advance

Hi @ravig1206 ,

We should be able to get the row Index from the Extracted Datatable using either the Look up Datatable activity or using a Linq Expression.

For the Linq Expression, we can check using the below Expression :

dr = DT.AsEnumerable.Where(Function(x)x("Product category").ToString andAlso x("Brand").ToString.Equals("FISKARS")).FirstOrDefault

here, dr is a variable of type DataRow.

We can then check if the dr contains any value using the below Condition in an If activity :

dr isNot Nothing

In the then block, we can use the below to get the row index :

rowIndex = DT.Rows.IndexOf(dr)

Here, rowIndex is a variable of type Integer.

@ravig1206

Try this
Index=Dt1.AsEnumerable.tolist.findindex(function(r) r(“Product category”).tostring.equals(“LANDSCRAPING”) and r(“Brand”).tostring.equals(“FISKARS”))

Hope this helps

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