Forum Discussion

tanacal's avatar
tanacal
Brass Contributor
Mar 02, 2025
Solved

PIVOTBY Table with custom sorting

Hi, does anyone know if there is way to custom sort the row of table made by PIVOTBY? Thanks,
  • PeterBartholomew1's avatar
    Mar 02, 2025

    I don't think there are any shortcuts but once you are into the 365 environment with LET you can define variables to use in place of helper ranges.

    = LET(
        index,    XMATCH(Category, CategoryOrder),
        crosstab, PIVOTBY(index, Year, Amount, SUM),
        rowHdr,   IFERROR(INDEX(CategoryOrder, TAKE(crosstab,,1)),""),
        HSTACK(rowHdr, DROP(crosstab,,1))
      )

    Here index is used for to sort the row categories and, once done, look up the appropriate row header.

     

Resources