Finding aggregated information of data
It is a bit hard to solve your problem without data but I tried to give it a go
with a how I think the data would be encoded. I used R with data.tables. You can read data.tables with fread().

Step 1

 require(data.table)

 # Assume sample_data has the following format:
 #   class: the class
 #   division: the division
 #   attendance: the attandance for a match
 #
 # I assume the table is in long format e.g. multiple rows exist per class with
 # per class one or different divisions.

 # Make the list of classes with at least 5 divisions.
 classes_of_interest &lt;- 
   sample_data[, 
               .(num_divisions = length(unique(divisions))),
               by = class][num_divisions &gt; 4, class]


Step 2

 # Only consider the classes that were in at least 5 divisions.
 attandance_by_division &lt;- 
   sample_data[class %in% classes_of_interest, 
               .(attendance = sum(num_people)),
               by = list(division, class)]
 setkey(attandance_by_division, "class")


Step 3

 # Merge the data set with a datas set that contains the required number
 # of attendants per class.
 # The  format is as follows:
 #   class: the class
 #   mininum_attendance: the minimum attendance
 attendance_data &lt;- 
   merge(attendance_requirements, 
         attandance_by_division, by = "class")

 # Here I exploit the fact that the true/false condition will be converted
 # to a 1 and 0. So I can sum and divide by the length of index subset created
 # by aggregating on 'class'.
 pct_of_division &lt;- 
   sample_data[, 
               .(pct_with_min_attendance = (sum(attendance &gt; minimum_attendance)
                                            / length(.I))),
                 by = class]


Hope this helps