AXLOOKUP

=AXLOOKUP(lv,la,ra,nf,m,s)

lv
array, lookup value
la
array, lookup array
ra
array, return array
nf
string, not found value
m
integer, match mode: 0 or ignored, exact match,-1 exact match or next smaller item, 1 exact match or next larger item, 2 wild character match
s
integer, search mode, 0, ignored or 1 search first to last, -1 search last to first

array XLOOKUP for 2D arrays

Xlambda

Well-known Member
Joined
Mar 8, 2021
Messages
860
Office Version
  1. 365
Platform
  1. Windows
AXLOOKUP array XLOOKUP for 2D arrays, carries XLOOKUP arguments except the binary ones of search mode. calls AFLATTEN
Excel Formula:
=LAMBDA(lv,la,ra,nf,m,s,
    LET(x,AND(OR(m={0,-1,1,2}),OR(s={0,1,-1})),sm,IF(s=0,1,s),
       fla,AFLATTEN(la),fra,AFLATTEN(ra),
       IF(x,XLOOKUP(lv,fla,fra,nf,m,sm),"check values")
    )
)
LAMBDA 6.0.xlsx
ABCDEFGHIJKLMN
1lookup arrayreturn array
212a1234b3.112345
3d4.11x1234a678910
4a23452a21112131415
53.9bx3456d4.91617181920
6
7looup valueregular XLOOKUP function=AXLOOKUP(A8:B9,A2:E5,G2#,,,)=AXLOOKUP(A8:B9,A2:E5,G2#,,,-1)
812#VALUE!#VALUE!m=012m=0815
9ab#VALUE!#VALUE!s=0104s=-11417
10
11=AXLOOKUP(A12:B13,A2:E5,G2#,"NA",,)=AXLOOKUP(A12:B13,A2:E5,G2#,,-1,)=AXLOOKUP(A12:B13,A2:E5,G2#,,-1,-1)
12bdnf="NA"46m=-146m=-11719
133.54.5m=0NANAs=057s=-157
14s=0input error
15=AXLOOKUP(A12:B13,A2:E5,G2#,,1,)=AXLOOKUP(A12:B13,A2:E5,G2#,,1,-1)=AXLOOKUP(A12:B13,A2:E5,G2#,,3,)
16m=146m=11719check values
17s=01620s=-11620
18=AXLOOKUP(A19:B19,A2:E5,G2#,,2,)=AXLOOKUP(A19:B19,A2:E5,G2#,,2,-1)
19a*x*m=239m=21418
20s=0s=-1
21
22regular XLOOKUP arguments are carried also by AXLOOKUP except the binary ones of search mode
23
24nf=not foundm=match modes=search mode
250 exact match1 search first to last
26-1 exact match or next smaller item-1 search last to first
271 exact match or next larger item
282 wild character match
29
30Obs.inside formula , if "s" is ignored or 0, will take the default XLOOKUP value 1
AXLOOKUP post
Cell Formulas
RangeFormula
G2:K5G2=SEQUENCE(4,5)
H7,K7,G18,D18,G15,J15,D15,D11,G11,J11H7=FORMULATEXT(H8)
D8:E9D8=XLOOKUP(A8:B9,A2:E5,G2#)
H8:I9H8=AXLOOKUP(A8:B9,A2:E5,G2#,,,)
K8:L9K8=AXLOOKUP(A8:B9,A2:E5,G2#,,,-1)
D12:E13D12=AXLOOKUP(A12:B13,A2:E5,G2#,"NA",,)
G12:H13G12=AXLOOKUP(A12:B13,A2:E5,G2#,,-1,)
J12:K13J12=AXLOOKUP(A12:B13,A2:E5,G2#,,-1,-1)
D16:E17D16=AXLOOKUP(A12:B13,A2:E5,G2#,,1,)
G16:H17G16=AXLOOKUP(A12:B13,A2:E5,G2#,,1,-1)
J16J16=AXLOOKUP(A12:B13,A2:E5,G2#,,3,)
D19:E19D19=AXLOOKUP(A19:B19,A2:E5,G2#,,2,)
G19:H19G19=AXLOOKUP(A19:B19,A2:E5,G2#,,2,-1)
Dynamic array formulas.
 
Upvote 0
This study was Inspired by Mike's ExcelIsFun latest 7 YT videos regarding the advantages of using good old LOOKUP functions.
1st :

7th:

Introducing LKP, a function that solves the endless debate of which lookup functions is better in various circumstances and also solves a big flaw of XLOOKUP's argument assigning that affects its performance considerably, compared with LOOKUP and VLOOKUP.
LKP is an All In One lookup function that combines the versatility and best performance out of all 4 lookup functions LOOKUP,VLOOKUP,HLOOKUP,XLOOKUP (plus, adds versatility of CHOOSECOLS/CHOOSEROWS arguments to use negative clm/row indexes. (like -1 for last row/clm) )

The concept is quite simple. All lookup functions need lookup value, lookup array (x) and return array (y) plus some arguments to trigger different behaviors or no other arguments at all.
LOOKUP specific functionality: when return array, ra, is omitted (2nd syntax of LOOKUP if la is 2D), if lookup array la is vertical (r>=c) => x=first column and y=last clmn of "la", respectively x=first row and y=last row if "la" is horizontal (r<c)
VLOOKUP/HLOOKUP specific functionality: x=first col/row of "la" and y=choosecols(la,clm index)/chooserows(la,row index)
LKP function embeds these functionalities and is designed to extract x and y for every possible scenario with the help of an additional options argument o as first argument, followed by the rest of the usual XLOOKUP arguments: lookup value(lv), lookup array (la), return array (ra), if not found (nf) , match mode (mm), search mode (sm)
LKP(o,lv,la,[ra],[nf],[mm],[sm]) All In One LooKuP custom made function
o: options argument: 0 or omitted, -1,1 or 2
o=0 or omitted => XLOOKUP functionality
o=-1 => return array ra is listening for rows index (like HLOOKUP)
o=1 => return array ra is listening for cols index (like VLOOKUP)
o=2 triggers LOOKUP
lv, la, ra, nf, mm, sm : xlookup's native arguments
Excel Formula:
=LAMBDA(o, lv, la, [ra], [nf], [mm], [sm],
    LET(
        i, ISOMITTED(ra),
        f, IF(ISOMITTED(nf), NA(), nf),
        r, ROWS(la),
        c, COLUMNS(la),
        v, r >= c,
        w, TAKE(la, , 1),
        l, TAKE(la, 1),
        k, IF(v, w, l),
        x, IF(OR(r = 1, c = 1), la, SWITCH(o, 0, k, -1, l, 1, w, 2, k)),
        y, IF(i, IF(v, TAKE(la, , -1), TAKE(la, -1)), SWITCH(o, 0, ra, 2, ra, -1, CHOOSEROWS(la, ra), 1, CHOOSECOLS(la, ra))),
        t, TOCOL(x),
        j, AND(t = SORT(t)),
        a, IF(j, 2, 1),
        IF(
            o = 2,
            IFNA(LOOKUP(lv, x, y), f),
            IF(AND(j, mm = -1, sm = -1), IFNA(LOOKUP(lv, x, y), f), LET(s, IF(sm, sm, IF(mm = -1, 1, a)), XLOOKUP(lv, x, y, nf, mm, s)))
        )
    )
)

@Excelambda All In One Lookup Functions.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAE
1Note: to compare LOOKUP VLOOKUP integration "la" was set in ascending order with dups and "lv" has values that returns results as exact or aprox match
2o, omitted => ra, not omitted => XLOOKUP functionality
3lvlara=LKP(,B4:D6,F4:F12,H4:H12,"x")=LKP(,B4:D6,F4:F12,H4:H12,"-",,-1)=LKP(,B4:D6,F4:F12,H4:H12,,1)
41231AADGCFIADG
50.51.52.51Bxxx---ADG
62.9933.011CxGx-I-GG#N/A
72D
82E=LKP(,B4:D6,F4:F12,H4:H12,,1,-1)=LKP(,B4:D6,F4:F12,H4:H12,,-1)=LKP(,B4:D6,F4:F12,H4:H12,,-1,-1)
92FCFIADGCFI
103GCFI#N/AAD#N/ACF
113HII#N/ADGGFII
123I
13
14o, omitted, ra, omitted => LOOKUP functionality using XLOOKUP's arguments
15lvla vertical array (r>=c)=LKP(,B16:D18,F16:I24)=LKP(,B16:D18,F16:I24,,"--",0,-1)=LKP(,B16:D18,F16:I24,,,1)
16123110100AADGCFIADG
170.51.52.5120200B#N/A#N/A#N/A------ADG
182.9933.01130300C#N/AG#N/A--I--GG#N/A
19240400D
20250500E=LKP(,B16:D18,F16:I24,,,1,-1)=LKP(,B16:D18,F16:I24,,,-1)=LKP(,B16:D18,F16:I24,,,-1,-1)
21260600FCFIADGCFI
22370700GCFI#N/AAD#N/ACF
23380800HII#N/ADGGFII
24390900I
25
26o, omitted, ra, omitted => LOOKUP functionality using XLOOKUP's arguments
27lvla horizontal array (r<c)=LKP(,B28:D30,F28:N31)=LKP(,B28:D30,F28:N31,,"",-1,-1)
28123111222333ADGCFI
290.51.52.5102030405060708090#N/A#N/A#N/ACF
302.9933.01100200300400500600700800900#N/AG#N/AFII
31ABCDEFGHI
32
33o,1 ra,clm index => VLOOKUP functionality using XLOOKUP's arguments
34lvla=LKP(1,B35:D37,F35:I43,-1,"")=LKP(1,B35:D37,F35:I43,3,"")=LKP(1,B35:D37,F35:I43,-2,"")=VLOOKUP(B35:D37,F35:I43,3,0)
35123110100AADG100400700100400700100400700
360.51.52.5120200B#N/A#N/A#N/A
372.9933.01130300CG700700#N/A700#N/A
38240400D
39250500E=LKP(1,B35:D37,F35:I43,4,"",1)=LKP(1,B35:D37,F35:I43,-3,"",-1)=LKP(1,B35:D37,F35:I43,-1,"",-1,-1)=VLOOKUP(B35:D37,F35:I43,4)
40260600FADG104070CFICFI
41370700GADG1040CF#N/ACF
42380800HGG407070FIIFII
43390900I
44
45o,-1 ra,row index => HLOOKUP functionality using XLOOKUP's arguments
46lvla
47123111222333
480.51.52.5102030405060708090
492.9933.01100200300400500600700800900
50ABCDEFGHI
51
52=LKP(-1,B47:D49,F47:N50,-1,"")=LKP(-1,B47:D49,F47:N50,3,"")=LKP(-1,B47:D49,F47:N50,-2,"")=HLOOKUP(B47:D49,F47:N50,3,0)
53ADG100400700100400700100400700
54#N/A#N/A#N/A
55G700700#N/A700#N/A
56
57=LKP(-1,B47:D49,F47:N50,4,"",1)=LKP(-1,B47:D49,F47:N50,-3,"",-1)=LKP(-1,B47:D49,F47:N50,-1,"",-1,-1)=HLOOKUP(B47:D49,F47:N50,4)
58ADG104070CFICFI
59ADG1040CF#N/ACF
60GG407070FIIFII
61
ex 1
Cell Formulas
RangeFormula
J3,O3,T3,F57,K57,P57,U57,P52,U52,F52,K52,Q39,V39,AA39,L39,AA34,V34,Q34,L34,V27,Q27,V20,Q20,L20,Q15,V15,L15,T8,J8,O8J3=FORMULATEXT(J4)
J4:L6J4=LKP(,B4:D6,F4:F12,H4:H12,"x")
O4:Q6O4=LKP(,B4:D6,F4:F12,H4:H12,"-",,-1)
T4:V6T4=LKP(,B4:D6,F4:F12,H4:H12,,1)
J9:L11J9=LKP(,B4:D6,F4:F12,H4:H12,,1,-1)
O9:Q11O9=LKP(,B4:D6,F4:F12,H4:H12,,-1)
T9:V11T9=LKP(,B4:D6,F4:F12,H4:H12,,-1,-1)
L16:N18L16=LKP(,B16:D18,F16:I24)
Q16:S18Q16=LKP(,B16:D18,F16:I24,,"--",0,-1)
V16:X18V16=LKP(,B16:D18,F16:I24,,,1)
L21:N23L21=LKP(,B16:D18,F16:I24,,,1,-1)
Q21:S23Q21=LKP(,B16:D18,F16:I24,,,-1)
V21:X23V21=LKP(,B16:D18,F16:I24,,,-1,-1)
Q28:S30Q28=LKP(,B28:D30,F28:N31)
V28:X30V28=LKP(,B28:D30,F28:N31,,"",-1,-1)
L35:N37L35=LKP(1,B35:D37,F35:I43,-1,"")
Q35:S37Q35=LKP(1,B35:D37,F35:I43,3,"")
V35:X37V35=LKP(1,B35:D37,F35:I43,-2,"")
AA35:AC37AA35=VLOOKUP(B35:D37,F35:I43,3,0)
L40:N42L40=LKP(1,B35:D37,F35:I43,4,"",1)
Q40:S42Q40=LKP(1,B35:D37,F35:I43,-3,"",-1)
V40:X42V40=LKP(1,B35:D37,F35:I43,-1,"",-1,-1)
AA40:AC42AA40=VLOOKUP(B35:D37,F35:I43,4)
F53:H55F53=LKP(-1,B47:D49,F47:N50,-1,"")
K53:M55K53=LKP(-1,B47:D49,F47:N50,3,"")
P53:R55P53=LKP(-1,B47:D49,F47:N50,-2,"")
U53:W55U53=HLOOKUP(B47:D49,F47:N50,3,0)
F58:H60F58=LKP(-1,B47:D49,F47:N50,4,"",1)
K58:M60K58=LKP(-1,B47:D49,F47:N50,-3,"",-1)
P58:R60P58=LKP(-1,B47:D49,F47:N50,-1,"",-1,-1)
U58:W60U58=HLOOKUP(B47:D49,F47:N50,4)
Dynamic array formulas.

@Excelambda All In One Lookup Functions.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1o,2 => triggers explicit LOOKUP function (nf can be used but the rest of xlookup arguments mm,sm have no relevance)
2lvlara=LKP(2,B3:D5,F3:F11,H3:H11)=LKP(2,B3:D5,F3:F11,H3:H11,"<")=LOOKUP(B3:D5,F3:F11,H3:H11)
31231ACFICFICFI
40.51.52.51B#N/ACF<CF#N/ACFany mm or sm values have no effect
52.9933.011CFIIFIIFII=LKP(2,B3:D5,F3:F11,H3:H11,"",1,1)
62DCFI
72Eif ra perpendicular to laCF
82FraFII
93GABCDEFGHI
103H
113I=LKP(2,B3:D5,F3:F11,J9:R9)=LKP(2,B3:D5,F3:F11,J9:R9,"<<")=LOOKUP(B3:D5,F3:F11,J9:R9)
12CFICFICFI
13#N/ACF<<CF#N/ACF
14FIIFIIFII
15
16lvla vertical array (r>=c)=LKP(2,B17:D19,F17:I25)=LOOKUP(B17:D19,F17:I25)
17123110100ACFICFI
180.51.52.5120200B#N/ACF#N/ACF
192.9933.01130300CFIIFII
20240400D
21250500E=LKP(2,B17:D19,F17:I25,,"--")
22260600FCFI
23370700G--CF
24380800HFII
25390900I
26
27lvla horizontal array (r<c)
28123111222333
290.51.52.5102030405060708090
302.9933.01100200300400500600700800900
31ABCDEFGHI
32
33=LKP(2,B28:D30,F28:N31)=LKP(2,B28:D30,F28:N31,,"na")=LOOKUP(B28:D30,F28:N31)
34CFICFICFI
35#N/ACFnaCF#N/ACF
36FIIFIIFII
37
ex 2
Cell Formulas
RangeFormula
J2,O2,T2,F33,K33,P33,L21,Q16,L16,J11,O11,T11,X5J2=FORMULATEXT(J3)
J3:L5J3=LKP(2,B3:D5,F3:F11,H3:H11)
O3:Q5O3=LKP(2,B3:D5,F3:F11,H3:H11,"<")
T3:V5T3=LOOKUP(B3:D5,F3:F11,H3:H11)
X6:Z8X6=LKP(2,B3:D5,F3:F11,H3:H11,"",1,1)
J12:L14J12=LKP(2,B3:D5,F3:F11,J9:R9)
O12:Q14O12=LKP(2,B3:D5,F3:F11,J9:R9,"<<")
T12:V14T12=LOOKUP(B3:D5,F3:F11,J9:R9)
L17:N19L17=LKP(2,B17:D19,F17:I25)
Q17:S19Q17=LOOKUP(B17:D19,F17:I25)
L22:N24L22=LKP(2,B17:D19,F17:I25,,"--")
F34:H36F34=LKP(2,B28:D30,F28:N31)
K34:M36K34=LKP(2,B28:D30,F28:N31,,"na")
P34:R36P34=LOOKUP(B28:D30,F28:N31)
Dynamic array formulas.

@Excelambda All In One Lookup Functions.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAA
1other examples
2 - single lookup value returns multiple results
3lv for all examples lv = 2
4lvla=LKP(,2,F5:F13,G5:I13)
5123110100A40400D
60.51.52.5120200B
72.9933.01130300C=LKP(,2,F5:F13,G5:I13,,,-1)
8240400D60600F
9250500E
10260600Flookup can not return multpl results for single lv
11370700G=LOOKUP(2,F5:F13,G5:I13)
12380800H#N/A
13390900I
14=LKP(1,2,F5:I13,{2,3,4})=VLOOKUP(2,F5:I13,{2,3,4},0)
1540400D40400D
16
17=LKP(1,2,F5:I13,{2,3,4},,,-1)=VLOOKUP(2,F5:I13,{2,3,4})
1860600F60600F
19
20 - ra omitted and la only is a vector, not 2D array
21
22lvla=LKP(,B23:D25,F23:F31,,"")=LKP(,B23:D25,F23:F31,,"",-1,-1)=LKP(2,B23:D25,F23:F31)=LOOKUP(B23:D25,F23:F31)
231231123123123123
240.51.52.5112#N/A12#N/A12
252.9933.0113233233233
262
272ra
282111222333
293
303=LKP(,B23:D25,H28:P28,,"")=LKP(,B23:D25,H28:P28,,"",-1,-1)=LKP(2,B23:D25,H28:P28)=LOOKUP(B23:D25,H28:P28)
313123123123123
3212#N/A12#N/A12
333233233233
34
ex 3
Cell Formulas
RangeFormula
L4,W30,M30,R30,H30,W22,M22,R22,H22,Q17,L17,Q14,L14,L11,L7L4=FORMULATEXT(L5)
L5:N5L5=LKP(,2,F5:F13,G5:I13)
L8:N8L8=LKP(,2,F5:F13,G5:I13,,,-1)
L12L12=LOOKUP(2,F5:F13,G5:I13)
L15:N15L15=LKP(1,2,F5:I13,{2,3,4})
Q15:S15Q15=VLOOKUP(2,F5:I13,{2,3,4},0)
L18:N18L18=LKP(1,2,F5:I13,{2,3,4},,,-1)
Q18:S18Q18=VLOOKUP(2,F5:I13,{2,3,4})
H23:J25H23=LKP(,B23:D25,F23:F31,,"")
M23:O25M23=LKP(,B23:D25,F23:F31,,"",-1,-1)
R23:T25R23=LKP(2,B23:D25,F23:F31)
W23:Y25W23=LOOKUP(B23:D25,F23:F31)
H31:J33H31=LKP(,B23:D25,H28:P28,,"")
M31:O33M31=LKP(,B23:D25,H28:P28,,"",-1,-1)
R31:T33R31=LKP(2,B23:D25,H28:P28)
W31:Y33W31=LOOKUP(B23:D25,H28:P28)
Dynamic array formulas.


Next post will be about the performance flaw of XLOOKUP solved by LKP's design.
 
Xlambda, You are a master mind of all masterminds : ) : ) It is just amazing that you created a single lookup formula that does everything. Are you a secret programmer at Microsoft? Probably the coolest thing in all this is that your arrays can listen for information! That means the genius programming is poetic and empathetic also : ) : )
 
Finally, vacation over, back to "school", back to posting from where we left off. Like always, Mike is too kind. Coming from the best Excel teacher in the world means a lot. 🙏
arg flaw.xlsx
ABCDEFGHIJKLMNOPQRSTUV
1The argument/parameter flaw of XLOOKUP. (context: lookup array "la" in ascending order)
2Binary Search is defined as a searching algorithm used in a sorted array by repeatedly dividing the search interval in half. .
3The idea of binary search is to use the information that the array is sorted and reduce the time complexity to O(log N)
4All old lookup functions, MATCH,LOOKUP,VLOOKUP, by default, are doing approximate match using the binary search algorithm=> super fast. Non binary search, by comparison is super slow.
5
6XLOOKUP syntax:
7 =XLOOKUP(lookup_value,lookup_array,return_array,[if_not_found], [match_mode], [search_mode])
8[match_mode]:[search_mode]:
90 exact match (default)1 search first to last (default)
10-1 exact match or next smaller item-1 search last to first
111 exact match or 2 binary search (la ascending order)
122 wildcard char match-2 binary search (la descending order)
13
14As we see, the only way to trigger binary search (for an ascending lookup array) is to call [search_mode] =2.
15
16"la" lkp arrayXLOOKUP to deliver same results
17asc with dups"lv" lkp val=LOOKUP(E19:E24,B19:C24)
18laralv↓↓=VLOOKUP(E19:E24,B19:C24,2)=XLOOKUP(E19:E24,B19:B24,C19:C24,,-1,-1)
19111222
20121.5222
21232444
22242.5444
23353666
24363.5666
25"ra" return array
26both, aprox match=> binary=> fastsince [srch_md] is already -1, can never be 2=> no binary search for last to first posiible
27if we force it to be 2 => other results, first to last, not what we want
28Conclusions:
29=XLOOKUP(E19:E24,B19:B24,C19:C24,,-1,2)
30LKP always checks if "la" is in ascending order, If Yes:1
31 - if [search_mode] is omitted will trigger XLOOKUP(lv,la,ra,,mm,2) => binary2
32 => for whatever [match _mode] chosen => binary search3
33The flaw:4
34 - if [search_mode] is -1 XLOOKUP can not perform binary search therefore 5
35LKP will trigger LOOKUP(lv,la,ra) which is binary6
36
37LKP borrows functionality from LOOKUP and VLOOKUP
38and is the most eficient when the others are not
39
40=LKP(,E19:E24,B19:B24,C19:C24,,-1,-1)
41↓↓=LKP(1,E19:E24,B19:C24,2,,-1,-1)
42↓↓↓↓=LKP(2,E19:E24,B19:C24)
43222
44222
45444
46444
47666
48666
49
50All 3 possible options of LKP to deliver same results and all are binary searches
51Next will test them speeds.
52
arg flaw
Cell Formulas
RangeFormula
G17,D41G17=FORMULATEXT(G19)
I18,M18,F42,M29I18=FORMULATEXT(I19)
G19:G24G19=LOOKUP(E19:E24,B19:C24)
I19:I24I19=VLOOKUP(E19:E24,B19:C24,2)
M19:M24M19=XLOOKUP(E19:E24,B19:B24,C19:C24,,-1,-1)
M30:M35M30=XLOOKUP(E19:E24,B19:B24,C19:C24,,-1,2)
B40B40=FORMULATEXT(B43)
B43:B48B43=LKP(,E19:E24,B19:B24,C19:C24,,-1,-1)
D43:D48D43=LKP(1,E19:E24,B19:C24,2,,-1,-1)
F43:F48F43=LKP(2,E19:E24,B19:C24)
Dynamic array formulas.
 
Mark's latest YT about XLOOKUP
Posted a comment about XLOOKUP flaw but was deleted (YT old flaw)
This is the comment:
Book1
A
1Great video !! Great examples !! Believe it or not , XLOOKUP(XMATCTH) has a big flaw. - consider this simple setup in this context :lookup array in ascending order, match mode: exact match or next smaller item A1:A6 B1:B6 1 A 2 B 2 C 3 D 3 E 4 F =VLOOKUP(2.5,A1:B6,2) returns C =LOOKUP(2.5,A1:B6) returns C To return C xlookup looks like this =XLOOKUP(2.5,A1:A6,B1:B6,,-1,-1) returns C The flaw : search_mode argument (last arg.) has to be -1 for search last to first like VLOOKUP and LOOKUP do natively aprox match If last arg has to be -1 can not be also 2 on the same time, so XLOOKUP con not perform binary search in this context and that means it will be dead slow, meanwhile VLOOKUP and LOOKUP are lighting fast since they do binary by default. The difference in time for large data sets or iterative algorithms is HUGE, hours instead of seconds. Conclusion: Whenever possible, sort lookup array and do binary search and if you need last to first do not use XLOOKUP, use VLOOKUP or LOOKUP. One day Excel will correct this. ✌🏼
Sheet1


XLOOKUP's match_mode and search_mode arguments
[match_mode]
Optional
Specify the match type:
0 - Exact match. If none found, return #N/A. This is the default.
-1 - Exact match. If none found, return the next smaller item.
1 - Exact match. If none found, return the next larger item.
2 - A wildcard match where *, ?, and ~ have special meaning.
[search_mode]
Optional
Specify the search mode to use:
1 - Perform a search starting at the first item. This is the default.
-1 - Perform a reverse search starting at the last item.
2 - Perform a binary search that relies on lookup_array being sorted in ascending order. If not sorted, invalid results will be returned.
-2 - Perform a binary search that relies on lookup_array being sorted in descending order. If not sorted, invalid results will be returned.
Book1
ABCDEFGHIJKLMNO
1XLOOKUP flaw in 3 seconds
2
3context:
4 -lookup_value: lv=2.5
5 -lookup_array: sorted ascending
6 -match_mode: -1 exact match or next smaller item
7 -search_mode: search last to first
8
9=VLOOKUP(2.5,B10:C15,2)
101AC
112B
122C=LOOKUP(2.5,B10:C15)
133DC
143E
154F=XLOOKUP(2.5,B10:B15,C10:C15,,-1,-1)
16C
17
18VLOOKUP and LOOKUP , native binary search in this context => super fast
19XLOOKUP can trigger binary search only if last argument is 2, but it's already -1
20
21 => in this context XLOOKUP is dead Slow compared with older brothers
22
Sheet2
Cell Formulas
RangeFormula
E9,E15,E12E9=FORMULATEXT(E10)
E10E10=VLOOKUP(2.5,B10:C15,2)
E13E13=LOOKUP(2.5,B10:C15)
E16E16=XLOOKUP(2.5,B10:B15,C10:C15,,-1,-1)
 
Beautifully said. I love LOOKUP : )

One day Microsoft will think through things clearly ; )
 

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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