Aggregating a stream of records
To aggregate is to combine many records into one summary value, such as a running total, a count of matching records, or an average worked out after the loop.
Understanding Aggregating a stream of records in QCE Digital Solutions Unit 2
What it does: The if limits the counting to matching records, and adding 1 each time combines them into a single count. An aggregate needs a starting value. A total starts at 0 so the first record is added to nothing. With no if, every record adds 1 to the count. The second option only counts records that match the condition. The total and count are only complete once the loop ends. Calculate the average after the loop for the final value. An empty stream leaves count at 0. Check that count > 0 before dividing.
Common mistakes: A running total must start at 0. Starting at 1 makes every final total one too high. It should be total ← 0. The file name is text, so it must be in quotes. It should be marks ← readFile("marks.csv").
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 186–228) and word search (Modules 144–228).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
aggregateFill in the Blanks
Spot the Error
Student with a class code? Join your class →