Dividing and filtering mass components based on different paramters easily

Hello !!
Basically i have different mass models placed for each level of buildings for one building and have 5 different houses in project which is all made of masses. I need to take volumes and floor area of each mass but before that i must divide and filter all these masses in project in this order (First is house number, second is level , balcony/terrace or other area) and all these parameters are given for each mass component in project and i need to filter and divide based on these parameters. I have done it but the script is so heavy. As you can see in the picture with red marekd area shows i filtered all masses for different house number and in next picture showed how i did this filtering. I know there will be easy method for filtering which will make script small for which i need your help.

@shershahbacha9 you certainly are doing it completely wrong
But you’ll need to upload relevant files, without which it would be difficult to help.

Yes i knew it was wrong and unprofessional.
ok lemme tell you in detail. I have 5 different houses all made of masses as shown in Picture A1. After that the components masses in each house are grouped by floor level (Geschoss) and other parameter R/S which shows its terrace/balcony or not. In Picture A2, you can see each mass when selected has these parameters Kommentare (R/S), Bauteil (House number) and Geschoss (floor level).
My task is to get volume, surface area and paerime

ter wall areas from each mass component but they should be grouped accordingly. For example House 1, then each level in house 1 and then R or S . Later i have to export these data to excel.
In picture A4 and A4.1Home.dyn (1.4 MB) , the green colored shows that long and unprofessional method of doing it , while in blue group on left side , now i am trying to do it shortly with help of long lists keeping focus on lacing. Picture A5 shows how i am dividing all masses to their houses, floor levels etc.
Also for getting surface area and wall parameter areas what i am doing is i explode the solid. In 6 surfaces, the first and last surfaces are the bottom and top surfaces respectively. So i separate ist and last surfaces from rest 4. The rest 4 i can find surface areas and that are my wall perimeter areas. The first two surfaces (which are bottom and top respectively). i take the bottom surface from it and take its surface area. Is it right or we do have other good method for extracting these things from solid cuboid.
i have uploaded the file named Home.dyn