AIF

AIF(a,e,[o])
a
array
e
expression criteria argument array
[o]
operation argument, 0 or omitted, multiplication or boolean AND ; 1, adding or boolean OR

Array Include argument for FILTER function, compact, complex calculations with boolean logic for an array of criteria. NEW!! REDUCE

Xlambda

Well-known Member
Joined
Mar 8, 2021
Messages
860
Office Version
  1. 365
Platform
  1. 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)
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
AIF.xlsx
ABCDEFGHIJKLMNOPQRS
1Examples 2. AIF with dates
2Saturdays and Sundays of November
3FriSatSunMonTueWedThu=AIF(WEEKDAY(A4#,2),{6,7},1)*AIF(MONTH(A4#),11)
401-10-2102-10-2103-10-2104-10-2105-10-2106-10-2107-10-210000000
508-10-2109-10-2110-10-2111-10-2112-10-2113-10-2114-10-210000000
615-10-2116-10-2117-10-2118-10-2119-10-2120-10-2121-10-210000000
722-10-2123-10-2124-10-2125-10-2126-10-2127-10-2128-10-210000000
829-10-2130-10-2131-10-2101-11-2102-11-2103-11-2104-11-210000000
905-11-2106-11-2107-11-2108-11-2109-11-2110-11-2111-11-210110000
1012-11-2113-11-2114-11-2115-11-2116-11-2117-11-2118-11-210110000
1119-11-2120-11-2121-11-2122-11-2123-11-2124-11-2125-11-210110000
1226-11-2127-11-2128-11-2129-11-2130-11-2101-12-2102-12-210110000
1303-12-2104-12-2105-12-2106-12-2107-12-2108-12-2109-12-210000000
1410-12-2111-12-2112-12-2113-12-2114-12-2115-12-2116-12-210000000
1517-12-2118-12-2119-12-2120-12-2121-12-2122-12-2123-12-210000000
1624-12-2125-12-2126-12-2127-12-2128-12-2129-12-2130-12-210000000
1731-12-2101-01-2202-01-2203-01-2204-01-2205-01-2206-01-220000000
1807-01-2208-01-2209-01-2210-01-2211-01-2212-01-2213-01-220000000
1914-01-2215-01-2216-01-2217-01-2218-01-2219-01-2220-01-220000000
2021-01-2222-01-2223-01-2224-01-2225-01-2226-01-2227-01-220000000
2128-01-2229-01-2230-01-2231-01-2201-02-2202-02-2203-02-220000000
22A4 forml:=SEQUENCE(18,7,"1-oct-21")
23Mon-Thu, for months Oct and Dec
24FriSatSunMonTueWedThu=AIF(WEEKDAY(A25:G42,2),{">=1","<5"})*AIF(MONTH(A25:G42),{10,12},1)
2501-10-2102-10-2103-10-2104-10-2105-10-2106-10-2107-10-210001111
2608-10-2109-10-2110-10-2111-10-2112-10-2113-10-2114-10-210001111
2715-10-2116-10-2117-10-2118-10-2119-10-2120-10-2121-10-210001111
2822-10-2123-10-2124-10-2125-10-2126-10-2127-10-2128-10-210001111
2929-10-2130-10-2131-10-2101-11-2102-11-2103-11-2104-11-210000000
3005-11-2106-11-2107-11-2108-11-2109-11-2110-11-2111-11-210000000
3112-11-2113-11-2114-11-2115-11-2116-11-2117-11-2118-11-210000000
3219-11-2120-11-2121-11-2122-11-2123-11-2124-11-2125-11-210000000
3326-11-2127-11-2128-11-2129-11-2130-11-2101-12-2102-12-210000011
3403-12-2104-12-2105-12-2106-12-2107-12-2108-12-2109-12-210001111
3510-12-2111-12-2112-12-2113-12-2114-12-2115-12-2116-12-210001111
3617-12-2118-12-2119-12-2120-12-2121-12-2122-12-2123-12-210001111
3724-12-2125-12-2126-12-2127-12-2128-12-2129-12-2130-12-210001111
3831-12-2101-01-2202-01-2203-01-2204-01-2205-01-2206-01-220000000
3907-01-2208-01-2209-01-2210-01-2211-01-2212-01-2213-01-220000000
4014-01-2215-01-2216-01-2217-01-2218-01-2219-01-2220-01-220000000
4121-01-2222-01-2223-01-2224-01-2225-01-2226-01-2227-01-220000000
4228-01-2229-01-2230-01-2231-01-2201-02-2202-02-2203-02-220000000
43
44first half of Oct and Dec
45FriSatSunMonTueWedThu=AIF(DAY(A46:G63),{">=1","<16"})*AIF(MONTH(A46:G63),{10,12},1)
4601-10-2102-10-2103-10-2104-10-2105-10-2106-10-2107-10-211111111
4708-10-2109-10-2110-10-2111-10-2112-10-2113-10-2114-10-211111111
4815-10-2116-10-2117-10-2118-10-2119-10-2120-10-2121-10-211000000
4922-10-2123-10-2124-10-2125-10-2126-10-2127-10-2128-10-210000000
5029-10-2130-10-2131-10-2101-11-2102-11-2103-11-2104-11-210000000
5105-11-2106-11-2107-11-2108-11-2109-11-2110-11-2111-11-210000000
5212-11-2113-11-2114-11-2115-11-2116-11-2117-11-2118-11-210000000
5319-11-2120-11-2121-11-2122-11-2123-11-2124-11-2125-11-210000000
5426-11-2127-11-2128-11-2129-11-2130-11-2101-12-2102-12-210000011
5503-12-2104-12-2105-12-2106-12-2107-12-2108-12-2109-12-211111111
5610-12-2111-12-2112-12-2113-12-2114-12-2115-12-2116-12-211111110
5717-12-2118-12-2119-12-2120-12-2121-12-2122-12-2123-12-210000000
5824-12-2125-12-2126-12-2127-12-2128-12-2129-12-2130-12-210000000
5931-12-2101-01-2202-01-2203-01-2204-01-2205-01-2206-01-220000000
6007-01-2208-01-2209-01-2210-01-2211-01-2212-01-2213-01-220000000
6114-01-2215-01-2216-01-2217-01-2218-01-2219-01-2220-01-220000000
6221-01-2222-01-2223-01-2224-01-2225-01-2226-01-2227-01-220000000
6328-01-2229-01-2230-01-2231-01-2201-02-2202-02-2203-02-220000000
64
65Saturdays and Sundays in 2022
66FriSatSunMonTueWedThu=AIF(WEEKDAY(A67:G84,2),{6,7},1)*AIF(YEAR(A67:G84),2022)
6701-10-2102-10-2103-10-2104-10-2105-10-2106-10-2107-10-210000000
6808-10-2109-10-2110-10-2111-10-2112-10-2113-10-2114-10-210000000
6915-10-2116-10-2117-10-2118-10-2119-10-2120-10-2121-10-210000000
7022-10-2123-10-2124-10-2125-10-2126-10-2127-10-2128-10-210000000
7129-10-2130-10-2131-10-2101-11-2102-11-2103-11-2104-11-210000000
7205-11-2106-11-2107-11-2108-11-2109-11-2110-11-2111-11-210000000
7312-11-2113-11-2114-11-2115-11-2116-11-2117-11-2118-11-210000000
7419-11-2120-11-2121-11-2122-11-2123-11-2124-11-2125-11-210000000
7526-11-2127-11-2128-11-2129-11-2130-11-2101-12-2102-12-210000000
7603-12-2104-12-2105-12-2106-12-2107-12-2108-12-2109-12-210000000
7710-12-2111-12-2112-12-2113-12-2114-12-2115-12-2116-12-210000000
7817-12-2118-12-2119-12-2120-12-2121-12-2122-12-2123-12-210000000
7924-12-2125-12-2126-12-2127-12-2128-12-2129-12-2130-12-210000000
8031-12-2101-01-2202-01-2203-01-2204-01-2205-01-2206-01-220110000
8107-01-2208-01-2209-01-2210-01-2211-01-2212-01-2213-01-220110000
8214-01-2215-01-2216-01-2217-01-2218-01-2219-01-2220-01-220110000
8321-01-2222-01-2223-01-2224-01-2225-01-2226-01-2227-01-220110000
8428-01-2229-01-2230-01-2231-01-2201-02-2202-02-2203-02-220110000
85
Examples 3
Cell Formulas
RangeFormula
I3,I66,I45,I24I3=FORMULATEXT(I4)
A4:G21A4=SEQUENCE(18,7,"1-oct-21")
I4:O21I4=AIF(WEEKDAY(A4#,2),{6,7},1)*AIF(MONTH(A4#),11)
B22B22=FORMULATEXT(A4)
I25:O42I25=AIF(WEEKDAY(A25:G42,2),{">=1","<5"})*AIF(MONTH(A25:G42),{10,12},1)
I46:O63I46=AIF(DAY(A46:G63),{">=1","<16"})*AIF(MONTH(A46:G63),{10,12},1)
I67:O84I67=AIF(WEEKDAY(A67:G84,2),{6,7},1)*AIF(YEAR(A67:G84),2022)
Dynamic array formulas.
 

Forum statistics

Threads
1,223,575
Messages
6,173,148
Members
452,502
Latest member
PQCurious

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top