+ Reply to Thread
Results 1 to 10 of 10

BYROW limitations: ranges vs. arrays

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    02-06-2013
    Location
    UK
    MS-Off Ver
    365
    Posts
    693

    BYROW limitations: ranges vs. arrays

    Hi, I've read a number of threads on the problems BYROW has, which I guess have mostly to do with not being able to handle arrays of arrays/nested arrays.

    Some common workarounds I've seen employ REDUCE which I find a bit unwieldy due to slow calculation speed with large data sets and REDUCE coming along with its own drawbacks, such as often involving dropping the first returned result (not always clear to me why) and and formulas delivering different results/not working at all depending on the initial value of e.g. '=REDUCE(,...' vs. '=REDUCE(0,...' vs. 'REDUCE("",...' (also not clear to me why).

    So I turned to MAP solutions which seems to be considered more robust in situations where BYROW fails.

    In the attached file I wrote down a common problem of BYROW that doesn't seem to exist with MAP.
    BYROW in that example works with a range reference, but not with a SEQUENCE-function containing the same as the referenced range nor with a TRANSPOSE-function of the referenced range.
    MAP works in all scenarios described.

    I found the following article (response by Sergei Baklan) quite helpful in navigating the situation, i.e. employing some =INDEX(i,1,1)-construct:
    https://techcommunity.microsoft.com/...ow/m-p/3777828
    It got the previously incorrectly working BYROW-formulas to return correct results in line with the results returned by MAP.

    However, I still don't think I fully understand what's going on here, so happy if somone maybe has some more useful explanation or reference for me on the topic of what exactly is the issue with BYROW here, why MAP works (but BYROW not), see e.g. the 2 questions raised in the Excel file.
    In some places this behaviour has been described as a bug, but it seems like not everybody agrees on this.
    Fundamentally it seems to come down to an array not being the same as a range reference in all circumstances/formulas alike?

    Similar to the following simplified problem:
    =SEQUENCE({2})
    returning 1 despite a formula evaluation shows the array,
    {1;2}
    which - upon pressing ENTER - spills correctly, whereas
    =SEQUENCE(INDEX({2},1))
    returns and spills correctly:
    {1;2}
    Compare this to e.g.:
    =SUM(1,2,{2})
    working without having to reference the array via INDEX.

    Any help, explanation or guidance for further reading is highly appreciated.

    Thanks
    Attached Files Attached Files
    Last edited by RaulSerg; 05-06-2024 at 08:03 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,800

    Re: BYROW limitations: ranges vs. arrays

    Maybe you need to consider BYCOL where the array is horizontal:

    =TRANSPOSE(BYCOL(D2#,LAMBDA(a,TEXTJOIN(", ",,SEQUENCE(5,,a)))))
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Valued Forum Contributor
    Join Date
    02-06-2013
    Location
    UK
    MS-Off Ver
    365
    Posts
    693

    Re: BYROW limitations: ranges vs. arrays

    Thanks, AliGW, it's a good point and you're right on that scenario.
    But I think it tackles my underlying question/problem only partially, as:
    =TRANSPOSE(BYCOL(SEQUENCE(,5),LAMBDA(a,TEXTJOIN(", ",,SEQUENCE(5,,a)))))
    still gives an incorrect result (all I did was replace the range reference with the formula that range contains), while MAP-ing the same does not:
    =TRANSPOSE(MAP(SEQUENCE(,5),LAMBDA(a,TEXTJOIN(", ",,SEQUENCE(5,,a)))))
    =TRANSPOSE(BYCOL(SEQUENCE(,5),LAMBDA(a,TEXTJOIN(", ",,SEQUENCE(5,,INDEX(a,1,1))))))
    does the job here similarly, too.

    It still puzzles me, I'm afraid.

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,870

    Re: BYROW limitations: ranges vs. arrays

    Map is designed to send a single value to the lambda, whereas bycol & byrow are designed to send a range/array to the lambda. So with bycol the variable "a" is sent as an array which sequence doesn't like.

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: BYROW limitations: ranges vs. arrays

    To add to Fluff13's comment. If you nest "a" in INDEX() it will convert array into single value and will work.
    Ex: =BYROW(TRANSPOSE(D2#),LAMBDA(a,TEXTJOIN(", ",,SEQUENCE(5,,INDEX(a,1)))))
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  6. #6
    Valued Forum Contributor
    Join Date
    02-06-2013
    Location
    UK
    MS-Off Ver
    365
    Posts
    693

    Re: BYROW limitations: ranges vs. arrays

    Thanks CK76.

    btw - for the sake of good order, this weird little thing also works.

    =BYROW(TRANSPOSE(D2#),LAMBDA(a,TEXTJOIN(", ",,SEQUENCE(5,,@a))))
    O.o
    Last edited by RaulSerg; 05-06-2024 at 12:05 PM.

  7. #7
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: BYROW limitations: ranges vs. arrays

    That's new array syntax.

    Sort of like [@TableColumn].

    It works within that formula construct, as Transpose(D2#) removes direct cell reference context.

    If you use it without, it's going to return #Value when you copy formula construct outside of row range in D2#.
    EX:
    =LET(a, $B$2#, @a)
    On the other hand...
    =LET(a, TRANSPOSE($D$2#),@a)
    This will always return 1.

  8. #8
    Valued Forum Contributor
    Join Date
    02-06-2013
    Location
    UK
    MS-Off Ver
    365
    Posts
    693

    Re: BYROW limitations: ranges vs. arrays

    Quote Originally Posted by CK76 View Post
    Sort of like [@TableColumn].
    Yup, I just saw this also mentioned and referenced here: https://support.microsoft.com/en-us/...e-c1c999be2b34

    What they're saying here:
    If the value is an array, then pick the top-left value.
    I guess is that this is effectively an alternative to doing a INDEX(i,1,1)-kinda thing.

    e.g.:
    =@SEQUENCE(5) = SINGLE(SEQUENCE(5)) = 1
    And similarly:
    =SEQUENCE({5}) 'incorrectly' shows 1 whereas =SEQUENCE(@{5}) = SEQUENCE(SINGLE({5})) spills correctly.

    Probably has some niche uses here or there.

  9. #9
    Valued Forum Contributor
    Join Date
    02-06-2013
    Location
    UK
    MS-Off Ver
    365
    Posts
    693

    Re: BYROW limitations: ranges vs. arrays

    Not exactly 100% sure what you mean, CK76?
    It seems to work irrespective of the TRANSPOSE-function in the various cases in my file that otherwise fail.

    btw - the @ seems to be equivalent to using the SINGLE()-function (which weirdly enough cannot be auto-completed).

  10. #10
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: BYROW limitations: ranges vs. arrays

    Ah, that's because BYROW/LAMBDA does same thing as TRANSPOSE.

    So you can copy paste formula, as 'a' loses cell reference context in evaluation. It will evaluate within context of LAMBDA iteration by row.
    Not relative to cell reference.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 12-07-2016, 07:41 AM
  2. [SOLVED] Ranges in selection and arrays
    By fgq in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-19-2013, 01:07 PM
  3. [SOLVED] How to use Arrays instead of Ranges
    By Sachy in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-10-2013, 10:54 AM
  4. Adding two Ranges/Arrays together
    By dbrutocao in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-19-2013, 06:37 PM
  5. arrays and ranges
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-05-2012, 12:18 PM
  6. size limitations of VBA arrays?
    By broro183 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-21-2009, 09:10 PM
  7. Ranges and Arrays
    By Will Brown in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-12-2005, 12:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1