Is it possible to sort table column values and display the header value in the next set of table columns

vampsthevampyre

New Member
Joined
Apr 29, 2016
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Evening Everybody

I'm looking to sort values in a table and then display the results sorted in the next table columns.

The table below shows what I'm looking to achieve with row 5 being Col1, Col2, Col3.

Tried a couple of things but keep getting spill errors, any help would be appreciated

Regards

Ian

roulette.xlsx
DEFGHIJ
3IDCol1Col2Col31stCol2ndCol3Col
41123Col1Col2Col3
52232Col1Col3Col2
63321Col3Col2Col1
74311Col2Col3Col1
85013
Sheet19
Cell Formulas
RangeFormula
D4:D8D4=ROW()-ROW(Table72[#Headers])
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hello, please test what @djclements recently posted in another thread:

Excel Formula:
=LET(
a,E4:G8,
IFNA(IF(1,WRAPROWS(SORTBY(TOCOL(a),TOCOL(IF({1},SEQUENCE(ROWS(a)),a)),1,TOCOL(ISNA(a)),1,TOCOL(a),1),COLUMNS(a)),a),""))
 
Upvote 0
Hello, please test what @djclements recently posted in another thread:

Excel Formula:
=LET(
a,E4:G8,
IFNA(IF(1,WRAPROWS(SORTBY(TOCOL(a),TOCOL(IF({1},SEQUENCE(ROWS(a)),a)),1,TOCOL(ISNA(a)),1,TOCOL(a),1),COLUMNS(a)),a),""))
It sort of works but still gets a spill array if placed in the table H4, also it only gives the values not the column headers
 
Upvote 0
So, something like:

Excel Formula:
=XLOOKUP(SMALL(Table72[@[Col1]:[Col3]],1),Table72[@[Col1]:[Col3]],Table72[[#Headers],[Col1]:[Col3]])

Excel Formula:
=IF(XLOOKUP(SMALL(Table72[@[Col1]:[Col3]],2),Table72[@[Col1]:[Col3]],Table72[[#Headers],[Col1]:[Col3]])=[@1stCol],XLOOKUP(SMALL(Table72[@[Col1]:[Col3]],2),Table72[@[Col1]:[Col3]],Table72[[#Headers],[Col1]:[Col3]],,,-1),XLOOKUP(SMALL(Table72[@[Col1]:[Col3]],2),Table72[@[Col1]:[Col3]],Table72[[#Headers],[Col1]:[Col3]]))

Excel Formula:
=IF(XLOOKUP(SMALL(Table72[@[Col1]:[Col3]],3),Table72[@[Col1]:[Col3]],Table72[[#Headers],[Col1]:[Col3]])=[@1stCol],XLOOKUP(SMALL(Table72[@[Col1]:[Col3]],3),Table72[@[Col1]:[Col3]],Table72[[#Headers],[Col1]:[Col3]],,,-1),XLOOKUP(SMALL(Table72[@[Col1]:[Col3]],3),Table72[@[Col1]:[Col3]],Table72[[#Headers],[Col1]:[Col3]]))
 
Upvote 0
Hello, please test what @djclements recently posted in another thread:

Excel Formula:
=LET(
a,E4:G8,
IFNA(IF(1,WRAPROWS(SORTBY(TOCOL(a),TOCOL(IF({1},SEQUENCE(ROWS(a)),a)),1,TOCOL(ISNA(a)),1,TOCOL(a),1),COLUMNS(a)),a),""))

That variant was customized for a situation involving #N/A errors. The same method could be applied here, but I might rewrite it like this:

Excel Formula:
=LET(
    idλ, LAMBDA(n,TOCOL(CHOOSE(n,Table72[[#Headers],[Col1]:[Col3]],Table72[ID]))),
    data, Table72[[Col1]:[Col3]],
    cols, COLUMNS(data),
    VSTACK(SEQUENCE(,cols)&"_Col",WRAPROWS(SORTBY(idλ({1}),idλ({2}),1,TOCOL(data),1),cols))
)

It's unfortunate the OP is asking to return the results within the same table. It would be fine in a neighboring column to the right of the table, in my opinion, but your alternative formulas for the three calculated columns should do the trick. ;)
 
Upvote 0
your alternative formulas for the three calculated columns should do the trick.
I don't think so unless sample data like row 9 below is not possible.

vampsthevampyre.xlsm
DEFGHIJ
3IDCol1Col2Col31stCol2ndCol3Col
41123Col1Col2Col3
52232Col1Col3Col2
63321Col3Col2Col1
74311Col2Col3Col1
85013Col1Col2Col3
96222Col1Col3Col3
Sheet1
Cell Formulas
RangeFormula
H4:H9H4=XLOOKUP(SMALL(Table72[@[Col1]:[Col3]],1),Table72[@[Col1]:[Col3]],Table72[[#Headers],[Col1]:[Col3]])
I4:I9I4=IF(XLOOKUP(SMALL(Table72[@[Col1]:[Col3]],2),Table72[@[Col1]:[Col3]],Table72[[#Headers],[Col1]:[Col3]])=[@1stCol],XLOOKUP(SMALL(Table72[@[Col1]:[Col3]],2),Table72[@[Col1]:[Col3]],Table72[[#Headers],[Col1]:[Col3]],,,-1),XLOOKUP(SMALL(Table72[@[Col1]:[Col3]],2),Table72[@[Col1]:[Col3]],Table72[[#Headers],[Col1]:[Col3]]))
J4:J9J4=IF(XLOOKUP(SMALL(Table72[@[Col1]:[Col3]],3),Table72[@[Col1]:[Col3]],Table72[[#Headers],[Col1]:[Col3]])=[@1stCol],XLOOKUP(SMALL(Table72[@[Col1]:[Col3]],3),Table72[@[Col1]:[Col3]],Table72[[#Headers],[Col1]:[Col3]],,,-1),XLOOKUP(SMALL(Table72[@[Col1]:[Col3]],3),Table72[@[Col1]:[Col3]],Table72[[#Headers],[Col1]:[Col3]]))


These would be my alternatives.

vampsthevampyre.xlsm
DEFGHIJ
3IDCol1Col2Col31stCol2ndCol3Col
41123Col1Col2Col3
52232Col1Col3Col2
63321Col3Col2Col1
74311Col2Col3Col1
85013Col1Col2Col3
96222Col1Col2Col3
Sheet1
Cell Formulas
RangeFormula
H4:H9H4=INDEX(SORTBY(Table72[[#Headers],[Col1]:[Col3]],Table72[@[Col1]:[Col3]]),1)
I4:I9I4=INDEX(SORTBY(Table72[[#Headers],[Col1]:[Col3]],Table72[@[Col1]:[Col3]]),2)
J4:J9J4=INDEX(SORTBY(Table72[[#Headers],[Col1]:[Col3]],Table72[@[Col1]:[Col3]]),3)
 
Upvote 0
Solution

Forum statistics

Threads
1,223,101
Messages
6,170,116
Members
452,302
Latest member
TaMere

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top