Perform average if in scripting

Good morning everyone,

I have a database of vegetables I purchased from several producers for my retail business. The database is structured as follow:
one vegetable (table 1) is being procured at a price (table 2) in a specific order (table 3) from specific producer (table 4).

I would need to get the past average cost of each vegetable for each producer, sth like an averageif (unit cost, past dates, producer A)
To my understanding, only scripting can do that. And Im new to it. What script should I write ?
Many thanks to everyone :))))
Good day !

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