Search code examples
google-sheets

Is there a way in Google Sheets to order cells in a range in the way depicted in the attached file and with one single formula?



In Google Sheets I have a situacion like this:
[![Cell reorder][1]][1]
https://i.sstatic.net/P2GZI.png

In column A:A I have some keys list, with an associated order (column B:B). Then I have some values in column E:E associated with the previous keys spread in column D:D and with a suborder (column F:F).

In column H:H I have the desired results; all the values listed, following their suborder, and grouped under the associated key, and everything ordered by the keys order takeb from column B:B. Besides that, the keys are prefixed and suffixed with several hypens.
I would like to achieve these results with one single formula located in cell H2, or cell H1 including the header (in the example I am using several sort & filter formulas).
Down below is the link to the spreadsheet in case you need it.
The formula should be able to accept as many keys, orders, values and suborders needed.

https://docs.google.com/spreadsheets/d/1XDaJFE_BYJpkhdq32iPHzucjf78mP2WCrDN76U5KwZM/edit?usp=sharing


Thank you.

Solution

  • You may try:

    =reduce("Header",tocol(sort(A2:A,B2:B,1),1),lambda(a,c,{a;"--- "&c&" ---";choosecols(sort(filter(E:F,D:D=c),2,1),1);if(,,)}))
    

    enter image description here