Implement common prefix aggregate function