Forum Discussion

LeeWhitt23's avatar
LeeWhitt23
Copper Contributor
Jan 22, 2024

Sorting

I’m trying to sort these columns by name but I need the lines for each employee to stay with their associated employee.   For example Caleb smith is employee number 1 and the three lines above him are associated with him so if I were to sort alphabetically it throws it off into a weird order.   Any help to get this sorted would be much appreciated!

  • LeeWhitt23 

    In a custom sort, you could sort on employee number first, then on material (or another column).

    That will keep the rows for each employee together.

  • djclements's avatar
    djclements
    Bronze Contributor

    LeeWhitt23 How about adding a calculated column to the table for the employee name? With the help of a separate employee lookup table, you could use the XLOOKUP function to accomplish this. For example:

     

    =XLOOKUP([@[EMP'#/LOCK'#]], tblEmployees[ID], tblEmployees[NAME])

     

    Then sort the table by the calculated "NAME" column from A to Z:

     

    Sort by Lookup Column

     

    Note: if the XLOOKUP function is not available in your version of Excel, use the INDEX / MATCH equivalent:

     

    =INDEX(tblEmployees[NAME], MATCH([@[EMP'#/LOCK'#]], tblEmployees[ID], 0))

     

    Please see the attached sample workbook...

Resources