If I remember correctly, in an earlier post, I suggested using a filter on a running total to filter out the contractors where the running total exceeded the goal. I can see that that approach filters out one too many contractors as it would filter out Dicks and Bobs instead of just Bobs.
I'm leaning towards a script like this that would need to be run to set the filter level in a global variable:
If [Not IsEmpty ( PortalRecords::PortalIDField) ]
Go To Related Record [Show only related records; From table: PortalTable; Using layout: "PortalTable" (PortalTable)]
Sort [No Dialog ; Restore ]//sort in ascending order by amount
Go To Record [first]
Exit Loop if [PortalTable:RunningTotal > parentTable::GoalAmt ]
Go To Record/Request/Page [Next ; Exit after Last]
Set Variable [$$FilterMax ; Value: PortalTable::RunningTotal]
Set Variable [$$OverGoal ; Value: Get ( FoundCount ) - Get ( RecordNumber ) + (PortalTable::RunningTotal > ParentTable::GoalAmt ) ]
Go To Layout [original layout]
Refresh Window [Flush cached Join Results]
If you then use this portal filter expression: PortalTable::RunningTotal < $$FilterMax, you see Toms through Dicks listed, but Bobs will be excluded.
Define a Count Of Summary field in the portal's table to count the number of records. Make a second portal to this same portalTable with the same filter, but with only one portal row and only this summary field in it. It will report your count of 3 companies.
$$Overgoal will report your 2 companies over the goal. You can use a number field in the parent table instead of this global variable if you want.