Select row value according to the value of another column

hello everyone,
this is what i need to do and i am trying to figure out the way to do it. i have to iterate throughout the columns and if the columns contains “SI” value then i need to save in a variable the value corresponsing under the column “COD_IVA”


for example i need to know that the column TA_31 contains “SI” and then assign the value “0I” to another variable. can someone suggest a solution? thank u

@olimpia.sannucci

  1. Read the data into Datatable(dt) using read range
  2. Use for each row in datatable activity
  3. Inside that use condition Currentrow("TA31_IMP").ToString.Equals("SI") and in the then side assign your variable with Currentrow("COD_IVA").ToString

you can also get all of them at once into an array(arr) using linq

arr = dt.AsEnumerable.Where(function(x) x("TA31_IMP").ToString.Equals("SI")).Select(function(x) x("COD_IVA").ToString).ToArray()

Hope this helps

cheers

Hi,

First use read range to read datatable in a variable and perform below operation:

at the end, write that table back to the excel sheet.

1 Like

how should i write it if the column name is dynamic? i mean, it is not always “TA31_IMP” but it should check all the other columns first. Because for example when it sees the column TA2_IMP it should see that there is “SI” and so save the value 12

@olimpia.sannucci

You want to check all the columns ? or any specific columns?

if all use a for loop inside to loop thorough each column as well and in the value of for loop use Enumerable.Range(0,dt.Columns.Count).ToArray and change the type argument to integer

and inside that use the if condition Currentrow(Currentitem).ToString.Equals("SI") like this…

this way it will check all the columns and if found use break to move to next row

cheers