Avoid XLookup to return Array

Carlos Matioli

New Member
Joined
May 15, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm trying to do a nested XLookup, as shown below. Inittially I will paste a "model" line, without any info. In the column P, I will do a nested XLookup, where I get the TextJoin of M:O to find this text in CabosNBR table headers. In the array returned, I search the value of column L, to get the cable section, which is my goal.

The thing is that if those cells (M:O) are blank and/or with values that don't match the CabosNBR table headers, the xlookup returns an array of all the cable sections.

How do I prevent this (xlookup do return array), showing a message or something like that if returns an array?

Ps.: the second xlookup needs to be "return the next larger item", because the value in the "L" column almost never matches the values in the CabosNBR data range.

Thank you for your time.



Cálculo cabo_rev1.xlsx
ABCDEFGHIJKLMNOP
1ItemTAG Circ.DEParaDescriçãoPotência [kVA]Potência [kW]FP Regime [%]FP Partida [%]Tensão [V]Nº FasesIb (A)Tipo de CaboMétodo Inst.
2201785,00%220352,49PVCA1PVC | A1 | 316
3201785,00%220326,100,5
40,75
51
61,5
72,5
84
96
1010
1116
1225
1335
1450
1570
1695
17120
18150
19185
20240
21300
22400
23500
24630
25800
261000
Cálculo
Cell Formulas
RangeFormula
L2L2=IF($K2=3,(F2*1000)/(J2*SQRT(3)),(F2*1000)/J2)
O2O2=TEXTJOIN(" | ",TRUE,M2:N2,K2)
G2:G3G2=F2*H2
P2:P26P2=XLOOKUP($L2, XLOOKUP($O2,CabosNBR[#Headers],CabosNBR[#Data],"Mét Inst Não Encontrado",0,1), CabosNBR[Seção],"Nada feito",1,2)
Cells with Data Validation
CellAllowCriteria
M2:M3ListPVC;EPR/HEPR
N2:N3List=INDIRETO("MetodoInst[Método]")


Cálculo cabo_rev1.xlsx
ABC
1Tipo caboPVCPVC
2Método InstA1A1
3Nº Cond23
4SeçãoPVC | A1 | 2PVC | A1 | 3
50,577
60,7599
711110
81,514,513,5
92,519,518
1042624
1163431
12104642
13166156
14258073
15359989
1650119108
1770151136
1895182164
19120210188
20150240216
21185273245
22240321286
23300367328
24400438390
25500502447
26630578514
27800669593
281000767679
Cabos
 
Thanks for the explanation. I did not realize that there might be some cases where values are missing from M,N, or O (or M,N,K...right?...since O is a TEXTJOIN that relies on the others). What do you want to happen in that case? Do you want the formula to stop at that point and return the message "Mét Inst Não Encontrado" in your results cell? And if so, would this message be displayed an any one or more of M,N,O are missing?
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Have a look at this...I think it might be a better approach. For your row 3 result, paste this formula:
Excel Formula:
=IF(OR($K3="",$M3="",$N3=""),
            "Mét Inst Não Encontrado",
            XLOOKUP($L3, FILTER(CabosNBR[#Data],(Cabos!$A$1:$AG$1=$M3)*(Cabos!$A$2:$AG$2=$N3)*(Cabos!$A$3:$AG$3=$K3),-99),CabosNBR[Seção],"Nada feito",1,1)  )
This first checks that K,M, and N are not blank...if any are then the formula stops and displays "Mét Inst Não Encontrado". If K,M, and N have values, then this array...
(Cabos!$A$1:$AG$1=$M3)*(Cabos!$A$2:$AG$2=$N3)*(Cabos!$A$3:$AG$3=$K3)
...identifies which column is of interest (identified by a 1, while all of the other column positions will be 0's). This column-matching array is passed to the FILTER function where the entire vertical array corresponding to the column match in CabosNBR is returned...and used in the next step with XLOOKUP. But suppose the values in K,M, or N are such that the column-matching array consists of all 0's...that is, there is no column in the CabosNBR table for the particular combination of K,M, and N. We tell FILTER to return a nonsense number...-99. So either the correct vertical array (column) from CabosNBR is sent to the XLOOKUP function or the number -99 (indicating an error) is sent to XLOOKUP. Next XLOOKUP attempts to find the value in L3 in either the matching column array or in the single item array holding the value -99. In the case where -99 is the lookup array, no match will be found, so the "Nada feito" message is returned. In cases where the CabosNBR matching-column array is the lookup array, XLOOKUP will find the best match unless the L3 lookup value is greater than the last lookup array entry or represents a nonsense value (e.g. if it is text), and in those cases it would also return the "Nada feito" message.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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