Created
February 24, 2025 14:44
-
-
Save ncalm/e309785e693437a651726a727cbce33e to your computer and use it in GitHub Desktop.
This Excel LAMBDA function allows us to pass 1, 2 and 3 sequences to the DATE function to produce complex lists of dates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DATE.EXP = LAMBDA(y, m, d, | |
LET( | |
mdJoin, CROSSJOIN(m, d), | |
ymdJoin, CROSSJOIN(y, mdJoin), | |
yearArray, CHOOSECOLS(ymdJoin, 1), | |
monthArray, CHOOSECOLS(ymdJoin, 2), | |
dayArray, CHOOSECOLS(ymdJoin, -1), | |
SORT(MAP(yearArray, monthArray, dayArray, DATE)) | |
) | |
); | |
/* | |
Name: Cross Join Two Arrays or Tables (CROSSJOIN) | |
Description: Returns all possible combinations of two arrays of data, with or without header rows. | |
If the arrays have only one row, it will be assumed that they are row vectors, otherwise it | |
assumes the arrays are columns of data. | |
Parameters: | |
array1 - first array of data with one or more columns | |
array2 - second array of data with one or more columns | |
[has_header_row] - true if the first row of the arrays contain a header row, default: false | |
Source: Excel Robot (@ExcelRobot) | |
Gist URL: https://gist.github.com/ExcelRobot/c96b9e129281ae18b239ef0d6e521c6a | |
*/ | |
CROSSJOIN = LAMBDA(array1, array2,[has_header_row], | |
LET( | |
HasHeader, IF(ISOMITTED(has_header_row), FALSE, has_header_row), | |
BothRowArrays, AND(ROWS(array1) = 1, ROWS(array2) = 1), | |
Data1, IF(BothRowArrays, TRANSPOSE(array1), IF(HasHeader, DROP(array1, 1), array1)), | |
Data2, IF(BothRowArrays, TRANSPOSE(array2), IF(HasHeader, DROP(array2, 1), array2)), | |
D1Cols, COLUMNS(Data1), | |
D2Rows, ROWS(Data2), | |
Reducer, MAKEARRAY(ROWS(Data1) * D2Rows, D1Cols + COLUMNS(Data2), | |
LAMBDA(i,j, | |
IF(j <= D1Cols, | |
INDEX(Data1, ROUNDUP(i / D2Rows, 0), j), | |
INDEX(Data2, MOD(i - 1, D2Rows)+1, j - D1Cols)) | |
) | |
), | |
IF( | |
BothRowArrays, | |
TRANSPOSE(Reducer), | |
IF(HasHeader,VSTACK(HSTACK(TAKE(array1, 1), TAKE(array2, 1)), Reducer), Reducer)) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment