Check two columns in datatable

Hello,

I want to create a function that checks if in an excel Data table in a row the cell in column A is filled + in column B if the cell says “order executed”. How do I write this together in one if statement?

Thank you!

Hi @lope_0238 ,

Try using this condition, that should to the trick.

not String.IsNullOrEmpty(dt_YourTable("ColumnA").ToString) and dt_YourTable("ColumnB").ToString.ToLower.Equals("order executed")

Thanks for your reply!

Unfortunately it doesn‘t work.
The column A contains integer values, maybe this is the reason?

If the column A is stored as int then is likely the empty values are passed as 0 or null therefore you should modify the condition to account for this.

Something like:

// option 1 if the value is passed as 0
dt_YourTable("ColumnA") <> 0 and dt_YourTable("ColumnB").ToString.ToLower.Equals("order executed")

//option 2 if the value is passed as null

dt_YourTable("ColumnA") isnot Null and dt_YourTable("ColumnB").ToString.ToLower.Equals("order executed")

On a side note, have you considered using Filter Data Table

https://docs.uipath.com/activities/docs/filter-data-table

Hello,

There is an easy way to accomplish this using Linq. I assume you want to check either if any of the rows in your datatable match the rule you described, or to get the rows that match the rule.

1. Check if any of the rows match the condition
Use this inside the ‘Condition’ block of the ‘If’ activity

dt.AsEnumerable.Any(function(x) x(0).ToString.Trim <> String.Empty andAlso x(1).ToString.Trim.ToUpper.Equals(“ORDER EXECUTED”) )

2. Return all the rows that match the condition
Use this in an ‘Assign’ activity, on the left side having a dataTable variable and on the right side the following condition:

dt.AsEnumerable.Where(function(x) x(0).ToString.Trim <> String.Empty andAlso x(1).ToString.Trim.ToUpper.Equals(“ORDER EXECUTED”) ).CopyToDataTable

In the conditions mentioned above, you have to replace the following:
dt - Replace this with the name of your dataTable through which you want to iterate

That’s it :slight_smile:

Let me know if you need any more help or info.

1 Like

It worked - thank you!
Is there also a way to rebuild the condition so that in column A it checks if today’s date is already in there (instead of just filled) + in column B if the cell says “order executed”?

Yes, there is:

dt.AsEnumerable.Where(function(x) x(0).ToString.Trim.Contains(DateTime.Now.ToString(“dd/MM/yyyy”)) andAlso x(1).ToString.Trim.ToUpper.Equals(“ORDER EXECUTED”) ).CopyToDataTable

Unfortunately this doesn‘t work…is there another linq?

I agree with Edwin. Use the filter data table activity. Don’t try to be a one-line hero when it’s not necessary.

Can you explain please how to do it with the filter data table activity? I’m sorry I’m a total noob in UiPath and still learning…

In the filter data table activity, you would select rows/columns you wish to remove/keep based off of column name and what the row should contain. You may then set the filtered data table to you input dt or a new dt variable. If you need further instruction, please refer to this:
Filter Data Table