Forum Discussion
PeterBartholomew1
Jul 09, 2022Silver Contributor
Filtering unordered records
This post contains a number of solutions to a problem of sorting arbitrarily ordered colours to pick out distinct combinations. I start with the formula as it should be, which sadly gives r...
SergeiBaklan
Jul 09, 2022MVP
That's interesting to play with it
sortRows=
LAMBDA( range,
LET(
topRow, SORT( CHOOSEROWS( range, 1),,, 1 ),
IF( ROWS(range) = 1,
topRow,
VSTACK( topRow, sortRows( DROP( range, 1 )))
)
));
distinctSortedRows=
LAMBDA( range,
UNIQUE( sortRows( range )));
checkSameRows=
LAMBDA( horizontalVector, array,
BYROW( array, LAMBDA( r, XOR( r = horizontalVector) )) );
getCountriesForColourCombination=
LAMBDA( horizontalVector,
TEXTJOIN(",",1,
IF( checkSameRows( horizontalVector, sortRows(colours) ),
country,""))
);
countriesByColourCombinations=
LET(
distinctColours, distinctSortedRows( colours ),
HSTACK( distinctColours,
BYROW( distinctColours, getCountriesForColourCombination ) )
);