Added check for empty data in grouping.calculation