Forum Discussion
PeterBartholomew1
Feb 20, 2022Silver Contributor
SUM not working with result from Lambda helper fn.
I picked up a banded commission problem from another forum and tried to apply routines I had written for FIFO allocation. It may have been a sledgehammer to crack an awkwardly shaped nut, but the La...
- Feb 20, 2022
This one works
= LET( commission, Allocateλ(+salesAmount,Bands, Rate), SUM(commission))The difference is in +salesAmount . Auto-lifting not always works.
PeterBartholomew1
Feb 20, 2022Silver Contributor
For what it is worth, these are the other named formulae
Accumulateλ = LAMBDA(arr, [init], [opening],
LET(
acc, SCAN(init, arr, Addλ),
open, IF(ISOMITTED(opening), 1, opening),
accumulated, IF(open, acc, acc - arr),
accumulated
)
);
Addλ = LAMBDA(x, y, (x + y));
Allocateλ = LAMBDA(outputArray, inputArray, [weight],
LET(
cumulativeOutput, Accumulateλ(outputArray, 0, {0, 1}),
cumulativeInput, Accumulateλ(inputArray, 0, {0, 1}),
m, ROWS(outputArray),
n, ROWS(inputArray),
allocationArray, MAKEARRAY(
m,
n,
LAMBDA(k, h,
LET(
u, {-1, 1} * INDEX(cumulativeOutput, k, {1, 2}),
v, {-1, 1} * INDEX(cumulativeInput, h, {1, 2}),
d, SUM(IF(u < v, u, v)),
q, IF(d > 0, d, 0),
w, IF(ISOMITTED(weight), 1, INDEX(weight, h)),
q * w
)
)
),
IF(ISOMITTED(weight), allocationArray, BYROW(allocationArray, Sumλ))
)
);
Diffλ = LAMBDA(s, [s0], [d],
MAKEARRAY(
ROWS(s),
COLUMNS(s),
LAMBDA(k, h,
LET(
a, INDEX(s, k, h),
b, IF(
d,
IF(
h > 1,
INDEX(s, k, h - 1),
IF(TYPE(s0) = 64, INDEX(s0, k), s0)
),
IF(
k > 1,
INDEX(s, k - 1, h),
IF(TYPE(s0) = 64, INDEX(s0, h), s0)
)
),
a - b
)
)
)
);
Expandλ = LAMBDA(rowϑ,
LET(
n₁, ROWS(INDEX(rowϑ, 1)()),
n₂, COLUMNS(rowϑ),
result, MAKEARRAY(
n₁,
n₂,
LAMBDA(i₁, i₂, INDEX(INDEX(rowϑ, 1, i₂)(), i₁))
),
result
)
);
Sumλ = LAMBDA(x, SUM(x));
ThunkByColλ = LAMBDA(array, BYCOL(array, Thunkλ));
Thunkλ = LAMBDA(x, LAMBDA(x));