Need help in building Linq Query

I have 2 data tables.

Lets say table 1 as

Table 2 as

Output should contain all the rows from Table 2 only.
if any row is not available in Table 1 - No need to make any changes
If matching row available in table 1- Subtract the point from Table2 with the point in Table 1 and keep the difference as the point

In above example - output should be

Hi @sharazkm32

Try this

dt_Output = (From row2 In dt_table2.AsEnumerable()
             Let match = dt_table1.AsEnumerable().FirstOrDefault(Function(row1) row1(0).ToString = row2(0).ToString)
             Let newPoint = If(match IsNot Nothing, Math.Abs(CInt(row2(1)) - CInt(match(1))), CInt(row2(1)))
             Select dt_table2.Clone().Rows.Add(row2(0), newPoint)).CopyToDataTable()

It works for me with the same inputs
Output:

Hope this helps!

2 Likes

It worked as expected. Thank You bro :victory_hand:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.