Forum Discussion

James_Buist's avatar
James_Buist
Brass Contributor
Oct 11, 2024

Another Spilled Array connundrum. Variant of a previous discussion that was solved.

Follow on from https://techcommunity.microsoft.com/t5/excel/another-dynamic-spilled-array-challenge-multiply-2-spilled/m-p/4263784   In this situation, I am trying to extend the concept of a previ...
  • djclements's avatar
    djclements
    Oct 13, 2024

    James_Buist Sure, if there's potentially other data in between the headcount sections, you could just VSTACK the applicable data instead of using SCAN:

     

    =LET(
        lookup_val, B15:B21 & "|" & F15:F21,
        lookup_arr, VSTACK(B4 & "|" & F5:F6, B7 & "|" & F8:F9, B10 & "|" & F11:F12),
        return_arr, VSTACK(I5:M6, I8:M9, I11:M12),
        factor, E15:E21,
        values, I15:M21,
        IFNA(INDEX(return_arr,XMATCH(lookup_val,lookup_arr),SEQUENCE(,COLUMNS(return_arr))),1)*values*factor
    )

     

    It's also possible to use the secondary syntax of INDEX and make use of the area_num argument; however, it will depend on the consistency of your headcount data (each area must have the same "entities" appearing in the same order, and all "codes" aside from 1 must be included):

     

    =LET(
        lookup_val, F15:F21,
        lookup_arr, F5:F6,
        codes,  B15:B21,
        driver, D15:D21,
        factor, E15:E21,
        values, I15:M21,
        IF(driver="Fixed",1,IFERROR(INDEX((I5:M6,I8:M9,I11:M12),XMATCH(lookup_val,lookup_arr),SEQUENCE(,COLUMNS(values)),codes-1),0))*values*factor
    )

     

    It's cleaner, but also easier to make a mistake if you have many entities/codes. 😉

Resources