Sorting based on reduced variable