Add sum_by function