Skip to content

Instantly share code, notes, and snippets.

@ncalm
Created December 11, 2024 19:51
Show Gist options
  • Save ncalm/886b5db7b5dcdc044ffd0ada78f09fa7 to your computer and use it in GitHub Desktop.
Save ncalm/886b5db7b5dcdc044ffd0ada78f09fa7 to your computer and use it in GitHub Desktop.
These Excel LAMBDA functions support extending TRIMRANGE to remove intermediary vectors from sparse references
CHECKRANGE = LAMBDA(checkfn,
LAMBDA(directionfn,
LAMBDA(v,
directionfn(v,LAMBDA(x,AND(checkfn(x))))
)));
CHECKISBLANK = CHECKRANGE(ISBLANK);
CHECKBLANKROWS = CHECKISBLANK(BYROW);
CHECKBLANKCOLS = CHECKISBLANK(BYCOL);
TRIMRANGE2 =LAMBDA(sparseRange, [compressOrRemove],
LET(
rng, TRIMRANGE(sparseRange),
maskFn, LAMBDA(v,
MAP(SEQUENCE(ROWS(v)), LAMBDA(i,
IF(i = 1, TRUE,
IF(
compressOrRemove,
NOT(INDEX(v, i)),
OR(
NOT(INDEX(v, i)),
AND(INDEX(v, i), NOT(INDEX(v, i - 1)))
)))))),
compressRows, FILTER(rng,maskFn(CHECKBLANKROWS(rng))),
TRANSPOSE(
FILTER(
TRANSPOSE(compressRows),
maskFn(TRANSPOSE(CHECKBLANKCOLS(rng)))
))));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment