Skip to content

Instantly share code, notes, and snippets.

@halbuki
halbuki / EXNUM
Created September 6, 2022 11:14
Excel Lambda functions for Power Query Number functions
/* USE NAMESPACE "Number" */
Abs = LAMBDA(_number, ABS(_number));
Acos = LAMBDA(_number, ACOS(_number));
Asin = LAMBDA(_number, ASIN(_number));
Atan = LAMBDA(_number, ATAN(_number));
@halbuki
halbuki / EXREP
Last active September 6, 2022 11:00
Excel Lambda functions for Power Query Replacer functions
/* USE NAMESPACE "Replacer" */
ReplaceText = LAMBDA(_text, _old, _new,
SUBSTITUTE(_text, _old,_new)
);
ReplaceValue = LAMBDA(_value, _old, _new,
IF(_value = _old, _new, _value)
);
@halbuki
halbuki / EXTEXT
Last active September 6, 2022 11:12
Excel Lambda functions for Power Query Text functions
/* USE NAMESPACE "Text" */
AfterDelimeter = LAMBDA(_text, delimiter, [_index], _text);
At = LAMBDA(_text, _index, MID(_text, _index, 1));
BeforeDelimeter = LAMBDA(_text, delimiter, [_index], _text);
BetweenDelimeters = LAMBDA(_text, _startDelimiter, _endDelimiter, [_startIndex], [_endIndex], _text);
@halbuki
halbuki / EXREC
Last active September 6, 2022 12:34
Excel Lambda functions for Power Query Record functions
/* USE NAMESPACE "Record" */
Field = LAMBDA(_record, _field,
LET(
fieldnames, Record.FieldNames(_record),
fieldcol, List.PositionOf(fieldnames, _field),
INDEX(_record, 2, fieldcol)
)
);
@halbuki
halbuki / EXTAB
Last active September 6, 2022 12:02
Excel Lambda functions for Power Query Table functions
/* USE NAMESPACE "Table" */
Item = LAMBDA(_table, _index,
MAKEARRAY(
2,
COLUMNS(_table),
LAMBDA(ir, ic, CHOOSE(ir, INDEX(_table, 1, ic), INDEX(_table, _index + 1, ic)))
)
);
@halbuki
halbuki / EXLIST
Last active September 7, 2022 08:03
Excel Lambda functions for Power Query List functions
/* USE NAMESPACE "List" */
Accumulate = LAMBDA(_list, _seed, _accumulator, REDUCE(_seed, _list, _accumulator));
AllTrue = LAMBDA(_list, AND(_list));
AnyTrue = LAMBDA(_list, OR(_list));
Average = LAMBDA(_list, AVERAGE(_list));
@halbuki
halbuki / EXARR
Last active September 1, 2022 17:41
Excel Lambda functions for array manipulation
REPLACENTH = LAMBDA(array, xnew, trow, [tcol],
LET(
tcol, MAX(tcol, 1),
MAKEARRAY(
ROWS(array),
COLUMNS(array),
LAMBDA(irow, icol,
IF(
AND(irow = trow, icol = tcol),
xnew,
@halbuki
halbuki / EXNAL
Last active September 1, 2022 14:41
Excel Lambda functions for numerical analyses
/* ROOTS OF FUNCTIONS */
BISEC = LAMBDA(f, lbound, ubound, [prec],
LET(
c, (lbound + ubound) / 2,
fl, f(lbound), fu, f(ubound), fc, f(c),
IF(
ABS(fc) < MAX(prec, 1E-15),
c,
IF(
SIGN(fl) = SIGN(fc),