add and display running totals on a form

add and display running totals on a form

so i have two forms Material In and Material out 

we get material from different sources so i have on my product in form (table)

product 1 
qty 10
from PO xxxxx

product 1 
qty 7 
from Job xxxx

On my product out form i have a look up field to another form called product type, upon entering the product type i have a field called product on hand and i would like this populated with the total number of products from the product in form. i am using :

if (Material_In[ID == input.Material_Type].count()  >  0)
{
    x  =  Material_In  [ID == input.Material_Type];
 
    input.QTY_On_Hand = x.QTY;
}
 

how ever it is not populating the field .... any suggestions?