DBD::CSV supports GROUP BY clauses, aggregate functions like SUM() and MAX(), and user-defined functions which can perform calculations on row values. See
SQL::Statement::Syntax for details. But first, it looks like you better read some SQL references on how to design your data structure and how to query your data to produce the results you want.