Xlambda
Well-known Member
- Joined
- Mar 8, 2021
- Messages
- 860
- Office Version
- 365
- Platform
- Windows
AIF Array Include argument for Filter function, NEW!! REDUCE. Returns array of 0 and 1 useful in FILTER function as include argument. Calls AFLAT , CP
Also, as "IF" in the function name suggests, (Array IF), same function will be used in replacing COUNTIFS,SUMIFS,…all …IFS functions complex constructions. For now, will cover what the function can do as Include argument in Filter function.
The goal of the function is to be able to do compact complex boolean logic with arrays of criteria that we can write explicitly or even can live in spreadsheet ranges for dashboard constructions.
a: array
e: expression criteria argument array ( "<=3" ,3, or {">=3",4,"*ab"} )
[o]: operation argument, 0 or omitted, multiplication or boolean AND ; 1, adding or boolean OR
For every criteria found in expression criteria argument array "e", applies the comparison function CP and multiplies or adds the results , depending on "o" argument value.
If "e" array has 3 elements e1,e2,e3, and "o" is 0 or omitted :
AIF(a,e)=CP(a,e1)*CP(a,e2)*CP(a,e3)
If "o"=1 :
AIF(a,e,1)=CP(a,e1)+CP(a,e2)+CP(a,e3)
CP(a,e) ComParison function. a,e arguments as in AIF
Also, as "IF" in the function name suggests, (Array IF), same function will be used in replacing COUNTIFS,SUMIFS,…all …IFS functions complex constructions. For now, will cover what the function can do as Include argument in Filter function.
The goal of the function is to be able to do compact complex boolean logic with arrays of criteria that we can write explicitly or even can live in spreadsheet ranges for dashboard constructions.
a: array
e: expression criteria argument array ( "<=3" ,3, or {">=3",4,"*ab"} )
[o]: operation argument, 0 or omitted, multiplication or boolean AND ; 1, adding or boolean OR
For every criteria found in expression criteria argument array "e", applies the comparison function CP and multiplies or adds the results , depending on "o" argument value.
If "e" array has 3 elements e1,e2,e3, and "o" is 0 or omitted :
AIF(a,e)=CP(a,e1)*CP(a,e2)*CP(a,e3)
If "o"=1 :
AIF(a,e,1)=CP(a,e1)+CP(a,e2)+CP(a,e3)
Excel Formula:
=LAMBDA(a,e,[o],LET(f,AFLAT(e),r,ROWS(f),IF(r=1,CP(a,e),LET(x,REDUCE(0,SEQUENCE(r),LAMBDA(v,i,v+CP(a,INDEX(f,i)))),IF(o,IF(x,1,0),IF(x=r,1,0))))))
CP(a,e) ComParison function. a,e arguments as in AIF
Excel Formula:
=LAMBDA(a,e,LET(x,LEFT(e,2),y,LEFT(e,1),z,SWITCH(x,"<=",x,">=",x,"<>",x,SWITCH(y,"<",y,">",y,"*",y,"!",y,"=")),w,SUBSTITUTE(e,z,"",1), v,IFERROR(--w,w),
--SWITCH(z,"<>",a<>v,"<=",a<=v,">=",a>=v,"<",a<v,">",a>v,"*",ISNUMBER(SEARCH(v,a)),"!",ISNUMBER(FIND(v,a)),"=",a=v)
)
)
Upvote
0