Added proper grouping in SQL query for report.