Fix grouping by PERIOD