Fix sorting of pivot tables