Vlookup code

Hello community!

Iam using this below code for vlookup
(From row in dt_Lookup.AsEnumerable
Join main in dt_SourceTable.AsEnumerable on
row(“PO_NO”).tostring Equals main(“PO NO”).TOString
Select dt_sourceTableClone.rows.Add(main(PO NO),row(PO_NO),main(ITEM NAME),main(ITEM Desc),main(QTY Pending),)main(Invoice Qty)).copytoDataTable

It is giving lot of duplicates and when jam manually applying vlookup iam getting proper data
Anyone have any other linq query.

@Priyesh_Shetty

what you wrote is more a join

try using join datatable activity with left or right based on what you need

also if you need something better to show data and explain requirement…as you already mentioned query is not giving expected results it can be anythign you need

cheers

@Anil_G tried using join dataTable also getting the result but it is giving lot of duplicates…How can i use firstOrDefault method in that so that i can take only matching rows.

@Priyesh_Shetty

what kind of duplicates?

is whole row duplicated? if yes use remove deplicates after that

else after join based on what you need you can get the first matched row

dt.AsEnumerable.Groupby(function(x) x("uniquecol").ToString).Select(function(x) x.First).CopyToDatatable

again you are askign somethign without showing data or how duplicates are formed

cheers

@Anil_G while applying vlookup for po number using join, instead of giving me 3 item name its giving me 6 items. Is there any alternate except vlookup as the volume of the data is high and i have also used vlookup activity but it is taking 15 minutes for the execution,because of high data volume.

@Anil_G do you have any other groupby code based on 2 column like if i have a PO NO column which contains same 3 PO NO’s but the ITEM Name of each PO NO will be unique.

@Priyesh_Shetty

please share sample input and output

cheers

@Anil_G i can share he image of that 2 dataTables

@Anil_G


My dt1 is DtLookup table and My dt2 is dtSourceTable i want to paste the result under TODAY Column.

@Priyesh_Shetty

Instead using formula or linq directly write the excel vlookup formula in thr first row then use auto fill range activity to fill the formula till the end

cheers

@Anil_G it is taking time because data is 1,00000.

Hi @Priyesh_Shetty can you share excel

@Akash_Javalekar1 due to organization restriction i cant share the file😪

Okay so you need to lookup in dt2 and write into dt1 right ?

@Akash_Javalekar1 i need to write the data in dt2 under today column,but when iam using join code it is giving me duplicates,

You want to write directly data from dt1 to dt2 not using any reference column? you want to copy only date right if i am not wrong?

@Akash_Javalekar1 i want to use vlookup in today column for PO NO so need a linq code for accurate vlookup.

@Priyesh_Shetty

If you use lookup activity it would take time…but above mentioned is different…

Anyways …try this…but i see diplicate po numbers in both dt…not sure how you want it to be handled…if you want to use any other column as well add condition in if accordingly

Invoke code with dt1 as in/out and dt2 as in

Dt1.AsEnumerable.ToList.ForEach(sub(r) r("ToDAY") = dt2.AsEnumerable.First(function(x) x("PO no").ToString.Equals(r("PONo").ToString)("StartDate").ToString)

Cheers

@Anil_G which column should i add instead of start date?

@Priyesh_Shetty

Which ever column you need from dt2 into today column

Cheers