Then please show the structure of your account dimension - to understand the hierarchy...
"The purpose of this script is to evaluate the total of each group of bank accounts (they are separated into parents for each bank "brand": e.g. Barclays, Lloyds, Citibank, etc.)" - not clear!