Conditional sum of integers from nested repeat groups

Welcome to the community, @hm11! Maybe this post discussed previously should help you solve your issue: