Skip to content

Instantly share code, notes, and snippets.

@ncalm
Created February 13, 2025 21:18
Show Gist options
  • Save ncalm/ebd265b6e2ca8430bc26f7d2062ccf99 to your computer and use it in GitHub Desktop.
Save ncalm/ebd265b6e2ca8430bc26f7d2062ccf99 to your computer and use it in GitHub Desktop.
This Excel LAMBDA functions enables simultaneous row and column filtering as well as 2D include arrays
IFOMITTED = LAMBDA(arg, then, IF(ISOMITTED(arg),then,arg));
// Collapse a boolean array to a boolean vector
COLLAPSE = LAMBDA(
array,
[collapse_with], // AND (default) or OR
[collapse_to], // 0 (default) = column or 1 = row
IF(collapse_to=0,BYROW,BYCOL)(array,IFOMITTED(collapse_with, AND))
);
// Filter both rows and columns at the same time
// allow 2D include arrays along both dimensions
FILTER.2D = LAMBDA(
data,
[include_rows],
[include_cols],
[collapse_rows_with],// AND (default) or OR
[collapse_cols_with],// AND (default) or OR
LET(
_include_rows, IFOMITTED(
include_rows,
EXPAND({TRUE},ROWS(data),1,TRUE)
),
_include_cols, IFOMITTED(
include_cols,
EXPAND({TRUE},1,COLUMNS(data),TRUE)
),
_collapse_rows_with, IFOMITTED(collapse_rows_with,AND),
_collapse_cols_with, IFOMITTED(collapse_cols_with,AND),
_collapsed_include_rows, COLLAPSE(_include_rows,_collapse_rows_with),
_collapsed_include_cols, COLLAPSE(_include_cols,_collapse_cols_with,1),
FILTER(FILTER(data,_collapsed_include_rows),_collapsed_include_cols)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment