• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

SEQUENCE in a LET formula not behaving as expected

p45cal

Well-Known Member
In exploring a formula-only solution to this this thread: https://chandoo.org/forum/threads/vlookup.50070/ I've come across an unexpected block.
To break the problem down into smaller steps I've started with the likes of
38067-38098
in a single cell (a string, not a calculation) and I was aiming to get 38067,38068,38069,38070,38071,38072 etc. in a column of cells.
So in the attached I put that string in cell A1. I've got the result I want in cell Q2 and spill range, but it uses helper cells.
In the attached, the problem formula is in cell D1; I was expecting output as in C1 but I only get a single number. What the f am I (or Excel) doing wrong?!
SEQUENCE isn't working. =LET(d,31,SEQUENCE(d)) works fine, why not in cell D1?
To debug I've put the same LET formula in cell K2:N2 with different final arguments to make sure I'm getting the expected results.

Of course, I might be going around the houses with this formula and there'll likely be more elegant formulae and would like to see them, but I'd still be interested to know why I'm not getting the expected result. I really don't expect to get a decent solution for Ram Chandran's thread unless I look to making lambda formulae, it might even encourage me to look at recursive lambdas, but I doubt I'll get the time. It's become more academic for me to know what I've done wrong.

If I mention @Peter Bartholomew perhaps he'll jump in with some comments?
 

Attachments

  • Chandoo50080.xlsx
    17.3 KB · Views: 13
Seems that @Fluff13 has sorted the problem. It appears that the INDEX formula has returned arrays
Code:
= TYPE(a) gives 64
= TYPE(b) gives 64
Modifying the INDEX formula to avoid defaulting the column index would return scalar values, so
Code:
= LET(
    a, VALUE(TEXTSPLIT(A2, , "-")),
    b, INDEX(a, 1, 1),
    c, INDEX(a, 2, 1),
    d, c - b,
    s, SEQUENCE(d),
    s
  )
works. An alternative is to allow 'd' to be calculated as an array but then use "@" to truncate the (1x1) array
Code:
= LET(
    a, VALUE(TEXTSPLIT(A2, , "-")),
    b, INDEX(a, 1),
    c, INDEX(a, 2),
    d, c - b,
    s, SEQUENCE(@d),
    s
  )
Would I have fallen into the trap? Quite possibly!
 
Back
Top