excelexcel-lambda

REDUCE with conditional VSTACK inside LAMBDA. Is it possible?


I'm trying to build a VSTACK from a dynamic range using REDUCE.

What I'm getting:

enter image description here

What I want (note ignored XX value)

enter image description here

Essentially, the question is how to use conditional HSTACK inside LAMBDA inside REDUCE. Here I want to ignore cells with "XX" as a value, and create a HSTACK'd dynamic spill.

I know I could just use FILTER but this is just a simple example, where I often want to do more complex conditional edits inside a reduce depending on the cell value and then HSTACK the results (or ignore).

I don't understand what the #N/A values are due to.

HSTACK works without the conditional i.e this works (append "%" and HSTACK): enter image description here


Solution

  • Practicing With the REDUCE Function

    =LET(data,A1:A6,exclude,"XX",suffix,"%",
        DROP(REDUCE("",data,LAMBDA(rr,r,
            IF(r=exclude,rr,HSTACK(rr,r&suffix)))),,1))
    

    enter image description here

    LAMBDA-Ready

    More Efficient Ways to Meet the Requirement (Hardly Relevant)

    MS365

    =LET(data,A1:A6,exclude,"XX",suffix,"%",
        TOROW(IFS(data<>exclude,data&suffix),2))
    

    Excel 2021

    =LET(data,A1:A6,exclude,"XX",suffix,"%",
        TRANSPOSE(FILTER(data&suffix,data<>exclude)))