Average data on subform based on date on main form

Average data on subform based on date on main form

Hi

I would like to take an average of a subform for certain months. The dates are located on the main form.

I tried using a code that returns an "error at null"


currentmonth = Delivery_Date.getMonth();
history = Purchase_Order_Items[Product_ZID = item.ID && Purchase_ZID.Delivery_Date.getMonth() == currentmonth];
averageprice = history.avg(Price_Unit_Inventory);

Thanks