excelexcel-formula

Using AND Function to Aggregate Results from Dynamic Evaluate Named Formula on Multiple Rows


Problem

Trying to create a formula that gets me to the result of cell G3 without the intermediary step of having 5 formulas (i.e. E3:E8) for each row of my Data Set

enter image description here

excel 

E3=EVAL_FORMULA(CONCAT(VALUETOTEXT(C3,1), A3, VALUETOTEXT(B3,1)))
G3=AND(E3:E8)

EVAL_FORMULA refers to =LAMBDA(x, EVALUATE(x)) in Name Manager

Data Set

R/C A B C
1 s v inp
2 >= 1 118
3 = N N
4 <= 0.8 38.7885904621149
5 = NPL NPL
6 = LDTV HDTV
7 = NPL_LDTV NPL_HDTV

'Calc Detail' Data

R/C H I J K L M
23 118 N 38.7885904621149 NPL HDTV NPL_HDTV

Methods Tested


Attempt #1

Result: Success when Using Direct Ranges but Fails (i.e. #VALUE! error) when Using Named Ranges with LET()/TOCOL()

Using Direct Ranges

excel 
        
I3=MAP(A3:A8,B3:B8,C3:C8,LAMBDA(s,val,input,
COUNTIF(input,s&val)))
        
K3=AND(MAP(A3:A8,B3:B8,C3:C8,LAMBDA(s,val,input,
COUNTIF(input,s&val))))

Using Named Ranges with LET()/TOCOL()

excel

I12=LET(
    ss,     A12:A17,
    vals,   B12:B17,
    inputs, TOCOL('Calc Detail'!$H23:$M23),
    MAP(
        ss,
        vals,
        inputs,
        LAMBDA(s,val,input,
            COUNTIF(input, s & val)
        )
    )
)

K12=AND(LET(
    ss,     A12:A17,
    vals,   B12:B17,
    inputs, TOCOL('Calc Detail'!$H23:$M23),
    MAP(
        ss,
        vals,
        inputs,
        LAMBDA(s,val,input,
            COUNTIF(input, s & val)
        )
    )
))

Attempt #2

Result: Success both when Using Direct Ranges and when Using Named Ranges with LET()/TOCOL()

Using Direct Ranges

excel

M3=MAP(
    A3:A8,
    B3:B8,
    C3:C8,
    LAMBDA(s,val,input,
        SWITCH(
            s,
            ">=", input >= val,
            "=",  input =  val,
            ">",  input >  val,
            "<",  input <  val,
            "<=", input <= val,
            "<>", input <> val,
            "Invalid Operator"
        )
    )
)

O3=AND(
    MAP(
        A3:A8,
        B3:B8,
        C3:C8,
        LAMBDA(s,val,input,
            SWITCH(
                s,
                ">=", input >= val,
                "=",  input =  val,
                ">",  input >  val,
                "<",  input <  val,
                "<=", input <= val,
                "<>", input <> val,
                "Invalid Operator"
            )
        )
    )
)

Using Named Ranges with LET()/TOCOL()

M12=LET(
    ss,     A12:A17,
    vals,   B12:B17,
    inputs, TOCOL('Calc Detail'!$H23:$M23),
    MAP(
        ss,
        vals,
        inputs,
        LAMBDA(s,val,input,
            SWITCH(
                s,
                ">=", input >= val,
                "=",  input =  val,
                ">",  input >  val,
                "<",  input <  val,
                "<=", input <= val,
                "<>", input <> val,
                "Invalid Operator"
            )
        )
    )
)

O12=AND(LET(
    ss,     A12:A17,
    vals,   B12:B17,
    inputs, TOCOL('Calc Detail'!$H23:$M23),
    MAP(
        ss,
        vals,
        inputs,
        LAMBDA(s,val,input,
            SWITCH(
                s,
                ">=", input >= val,
                "=",  input =  val,
                ">",  input >  val,
                "<",  input <  val,
                "<=", input <= val,
                "<>", input <> val,
                "Invalid Operator"
            )
        )
    )
))

Solution

  • There can be problems using a named Excel 4 macro inside a LAMBDA function on the worksheet. In your simplified example, I would suggest using the MAP and SWITCH functions instead:

    =MAP(
        A2:A7,
        B2:B7,
        C2:C7,
        LAMBDA(s, v, inp,
            SWITCH(
                s,
                ">=", inp >= v,
                "=", inp = v,
                "<=", inp <= v,
                "<>", inp <> v,
                "Invalid Operator"
            )
        )
    )
    

    enter image description here