@bines53
David,
Lambda is well worth the time invested. It is at the core of modern Excel and changes the way in which solutions are planned and implemented. Instead of working at a uniformly detailed level, functionality can be built at the detailed level but then combined to form solutions to conceptually more advanced problems.
Pascal.
Your combination of SMALL and MAKEARRAY works really well for this problem! My congratulations. I also note your reference to Sergei Balkan's work. Sergei is very good, well worth following. As Sergei suggests the solution to sorting by row should be
Code:
= BYROW(range, LAMBDA(r, SORT(r)))
It was only a monumentally poor piece of decision making on behalf of Microsoft that causes this to fail. The 'logic' was 'Excel has always failed to process arrays of arrays so, for the sake of backward compatibility, modern Excel should also fail'!
The problem I have found with MAKEARRAY is that one often finishes performing the same array calculation repeatedly but picking one result out at a time, so the calculation can become spectacularly inefficient if you have 1000s or columns. In the attached, I have used Thunks and VSTACK, though there is an element of overkill applied to the present problem.
Code:
= LET(
sortedϑ, BYROW(data, SortRowλ),
REDUCE(hdr, sortedϑ, StackRowλ)
);
SortRowλ
= LAMBDA(r,LAMBDA(SORT(r,,-1,1)));
StackRowλ
= LAMBDA(acc,ϑ,VSTACK(acc,ϑ()));
The steps involve sorting row by row but using a further LAMBDA to return the result as a column of functions which take a null parameter string (thunks).. The second Lambda function expands each of these back to a row and stacks them vertically to give the result.
Overall, what should have been a simple formula is turned into an advanced programming exercise, That is not good!