Skip to content

Instantly share code, notes, and snippets.

@ncalm
Created April 26, 2024 12:41
Show Gist options
  • Save ncalm/3fc1f027ae8c5b550d96e7e014248c6f to your computer and use it in GitHub Desktop.
Save ncalm/3fc1f027ae8c5b550d96e7e014248c6f to your computer and use it in GitHub Desktop.
This Excel LAMBDA function implements the functionality of F#'s List.allPairs function for creating a cross-join between two lists (vectors)
LIST.ALLPAIRS = LAMBDA(list1, list2,
LET(
list1Col, TOCOL(list1),
list2Col, TOCOL(list2),
list1length, ROWS(list1Col),
list2length, ROWS(list2Col),
resultRows, SEQUENCE(list1length * list2length, 1),
rowIndex1, CEILING(resultRows / list2length, 1),
rowIndex2, MOD(resultRows - 1, list2length) + 1,
HSTACK(INDEX(list1Col, rowIndex1), INDEX(list2Col, rowIndex2))
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment