I think what you're probably going to need to do is set up a relationship between the table occurrence that's shown in the left portal and the one in the right portal. Then create a calculation field in the left TO that calculates your needed total, based on that relationship. If needed, you can use Conditional Formatting or an alternative result in the calculation to hide the result until needed (perhaps setting a field when you execute the script that sets the portal filter).
Hope that makes sense.
I got it working with the relationship and a simple script to set variable and set field.