Sorting according to period