You could do this by a regular process that runs through all products but that could be a bit wasteful. The alternative which would require more effort to get right in all instances is to write an extension that listens for product update events and then performs the calculation at that point.
This stackoverflow post shares a couple of the events that you would need to listen to: https://magento.stackexchange.com/a/9068/26
catalog_product_save_before
catalog_product_attribute_update_before
----
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!