Fixed a condition that determines grouping for getting subtotals.