Linq for Compare Two Columns in Different DT and Update in DT1

Hi All,

I have 2 DT as DT1 and DT2, It has Column Region and Unit, If DT1 Region is empty it has to fill the fill the region with the help of Dt2 by Using the Column Unit Using Linq attached sample below

DT1 DT2
Region Unit Region Unit
US US371 US US371
India US943 US US943
Australia US528 US US528
US715 US US890
UK US890 Europe US715
Output DT
Region Unit
US US371
India US943
Australia US528
Europe US715
UK US890

Thanks in advance

Hey @Manii_K

Please try this project:
BlankProcess22.zip (35.1 KB)

You can also use this example of linq:

(From row In dt1.AsEnumerable()
 Let filledRegion = If(String.IsNullOrWhiteSpace(row("Region").ToString.Trim),
                       dt2.AsEnumerable().
                          Where(Function(r2) r2("Unit").ToString = row("Unit").ToString).
                          Select(Function(r2) r2("Region").ToString).
                          FirstOrDefault(),
                       row("Region").ToString)
 Select outputDT.Rows.Add({filledRegion, row("Unit").ToString})
).CopyToDataTable()

2 Likes

@Manii_K

Use invoke code activity and send dt1 as in/out and dt2 as in arguments

Dt1.AsEnumerable.
Where(function(x) string.IsNullOrEmpty(x(0).ToString)).
ForEach(sub(x) x(0) =dt2.AsEnumerable.
where(function(y) y(1).ToString.Equals(x(1).ToString).
Select(function(y) y(0).ToString).First)

Cheers

Hi @pikorpa Thanks for your time

1 Like

Hi @Anil_G Thank you so much

1 Like