Search code examples
google-sheetsgoogle-sheets-formula

How can I sort a column horizontally into transposed rows with matching prefixes?


I have a google sheet column with data that looks like this. ID numbers with count suffixes. How can I transpose them horizontally into rows on a sheet sorted/grouped/filtered by their ID number into the appropriate number of columns matching their suffix number?

Sheet Link: https://docs.google.com/spreadsheets/d/1wq3Zrh5wE_IHP2utvMeFRHrMe1qra2ppq_G7PrSt-jY/edit?usp=sharing

What I have
INV46673-1
INV46673-2
INV56184-1
INV56184-2
INV56184-3
INV56184-4
INV56184-5
INV68328-1
INV68328-2
INV68328-3
INV68328-4
INV68347-1
INV68347-2
INV68347-3
What I need
INV46673-1 INV46673-2
INV56184-1 INV56184-2 INV56184-3 INV56184-4 INV56184-5
INV68328-1 INV68328-2 INV68328-3 INV68328-4
INV68347-1 INV68347-2 INV68347-3

If sheets has an off the shelf function for this I have not been able to find it. I have tried pivot tables, Hlookup, filtered arrays etc. I am grateful for any advice I may receive. A solution that uses a fixed character count (8) will work but I would love to see something that actually uses the exact ID number.


Solution

  • Try the following formula-

    =INDEX(SPLIT(BYROW(UNIQUE(INDEX(SPLIT(A2:A15,"-"),,1)),LAMBDA(x,JOIN("|",SORT(FILTER(A2:A15,INDEX(SPLIT(A2:A15,"-"),,1)=x))))),"|"))
    

    enter image description here