I have a similar need for my application. In this regard I’ve been keeping a close eye on similar posts and requests.
At best, my current logic (yet to be implemented) will be to create a series of counter fields to maintain a total sum for each, where I will increment and decrement by 1, with a Workflow, each time a change is made, to keep a accurate total count.
Then, periodically I will run a Bulk Action to read the entire file, record by record, to check and or update the sum counters. Here’s a good link on Bulk Actions: