I am currently using a code in Invoke Code Activity, attaching the same below.
downloadedfile_DT.AsEnumerable().ToList().ForEach(Sub(row) row(“Difference”)=CDbl(row(“Rate/Unit”).ToString)-CDbl(row(“Price from Price Master”).ToString))
This code is working absolutely code for me. But in this case, in this for each loop, i want to add an if condition that for only non null values of “Rate/Unit” Column and “Price from Price Master” column needs to be subtracted. Pease help me with the same.
Thanks in Advance.
Hello @yash.choursia
Please try below and let us know the result
dt_Input.AsEnumerable().ToList().ForEach(Sub(row) row("Difference")=CDbl(If(String.IsNullOrWhiteSpace(row("Rate/Unit").ToString,"0.0",row("Rate/Unit").ToString)-CDbl(String.IsNullOrWhiteSpace(row("Price from Price Master").ToString,"0.0",row("Price from Price Master").ToString))
It will replace all null values with zero
I recommend to use Where method instead of If operator in ForEach, as the following.
downloadedfile_DT.AsEnumerable().Where(Function(r) r("Price from Price Master") isnot Nothing AndAlso not String.IsNullOrEmpty(r("Price from Price Master").ToString) AndAlso r("Rate/Unit") isnot Nothing AndAlso not String.IsNullOrEmpty(r("Rate/Unit").ToString) ).ToList().ForEach(Sub(row) row("Difference")=CDbl(row("Rate/Unit").ToString)-CDbl(row("Price from Price Master").ToString))