Search code examples
linquipathuipath-studiouipath-activity

Need to change the lookup column in LINQ Vlookup in UiPath


I have the lookup value in the 11 column. While executing the below code it picking up the first column of my input excel file. So i need to change the lookup value from 1st column to 3rd column(example my source lookup value is in 3rd coulmn).in the below code where i need to change the column.

(From d In dtData1.AsEnumerable
Let check = dtData2.AsEnumerable.Where(Function (r)r(0).toString.Trim.Equals(d(0).toString.Trim)).toList
Let c2 = If(check.Count() > 0, check(0)(0), "")
Let ra = {d(0), c2}
Select dtResult.Rows.Add(ra)).CopyToDataTable


Solution

  • Assuming that dtData2 is your table where you want to lookup the value in 3rd column then use the below code

    (From d In dtData1.AsEnumerable
    Let check = dtData2.AsEnumerable.Where(Function (r)r(2).toString.Trim.Equals(d(0).toString.Trim)).toList
    Let c2 = If(check.Count() > 0, check(0)(0), "")
    Let ra = {d(0), c2}
    Select dtResult.Rows.Add(ra)).CopyToDataTable
    

    In the above code, I have change r(0).ToString to r(2).ToString. I would recommend using a column name instead of an index so that you get a better understanding of LINQ.