Subtact from two data table

Hello Team,

We have Sheet1 with Below data

We have Sheet2 with Below Data

How can we get Sheet 3 in below format based on Subtraction done

Example
In Sheet 1 Product Column 89 -Sheet 2 Product Column 89 = 0

Which is Updated in Sheet 3

Have attached Excel Sheet for Reference which contains Expected format of Sheet 3
Test dt (1).xlsx (7.4 KB)

Look forward to you suggestions

Thanks in advance

Hi @NISHITHA

Read the Sheet1 to datatable as dt_input and Sheet2 to dt_input2, Use the below linq

dt_Result= dt_input.AsEnumerable().SelectMany(Function(row1) dt_input2.AsEnumerable().Where(Function(row2) CType(row2("SupplyId"), String) = CType(row1("SupplyId"), String)).Select(Function(x) dt_input.Clone().LoadDataRow({x("SupplyId").ToString(), CDbl(row1("Product")) - CDbl(x("Product")), CDbl(row1("KeyProducts")) - CDbl(x("KeyProducts"))}, False))).CopyToDataTable()

Write the dt_Result to Sheet3 which solves your usecase!

Output:
image

Do mark it as a solution if it helps you!

Thank You

1 Like

Any specific reason why you want to try via Data table only and not using Excel Formulas?

Thanks @Sanjay_Bhat it works

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