Why don't these LOOKUP functions work?

tigerzen

Board Regular
Joined
Mar 8, 2023
Messages
165
Office Version
  1. 365
Platform
  1. Windows
Book4
ABCDEFGHI
1HRSalesFinanceExisting department
2TomYes#N/AFALSETRUEFALSE
3PeteYes#N/ATRUEFALSEFALSE
4Fred#N/AFALSEFALSEFALSE
5SallyYesYesFALSEFALSETRUE
Sheet1
Cell Formulas
RangeFormula
E2E2=LOOKUP(1,B2:D2<>"",B2:D2)
E3:E4E3=LOOKUP("TRUE",(B3:D3<>""),B3:D3)
E5E5=LOOKUP(2,1/(B5:D5<>""),B5:D5)
G2:I5G2=B2:D2<>""
Dynamic array formulas.


Trying to understand why the formulae in Rows 2 and 3 show errors, ie for Tom and Pete. Columns G to I with the relevant tests show that there are TRUE values but they aren't being picked up by the Lookup values in the formulae.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
in E2 try
Excel Formula:
=LOOKUP(1,1/(B2:D2<>""),B2:D2)
Thanks Sanjay, that does indeed work but I'm trying to grasp why the other formulae don't work. The division by 1 converts TRUE/FALSE to numbers but shouldn't the formulae for Pete work? Also noticed that if I change the formula to LOOKUP(1,1*(B2:D2<>""),B2:D2) and copy down, it only works for the first record, see attached spreadsheet.
Book4
ABCDEFGHI
1HRSalesFinanceExisting department
2TomYesYesFALSETRUEFALSE
3PeteYes0TRUEFALSEFALSE
4Fred0FALSEFALSEFALSE
5SallyYes0TRUEFALSEFALSE
Sheet1
Cell Formulas
RangeFormula
E2:E5E2=LOOKUP(1,1*(B2:D2<>""),B2:D2)
G2:I5G2=B2:D2<>""
Dynamic array formulas.
 
Upvote 0
Why don't these LOOKUP functions work?
To answer your question ..
E2 formula does not work because it is looking for numbers in B2:D2 are there are no numbers. Hence the #N/A result.
E3:E4 formula does not work because it is looking for a text value but (B3:D3<>"") produces an array of logical True/False results, not text "True"/"False" results. Hence the #N/A result.

Here are three other options that you could consider, depending on whether it is possible for somebody to be in more than one department (see row 6).

23 05 02.xlsm
ABCDEFG
1HRSalesFinanceExisting departmentExisting departmentExisting department
2TomYesYesYesYes
3PeteYesYesYesYes
4Fred#N/ANo 
5SallyYesYesYesYes
6AnnYesYesYesYesYesYes
Existing Dept
Cell Formulas
RangeFormula
E2:E6E2=LOOKUP("z",B2:D2)
F2:F6F2=IF(COUNTIF(B2:D2,"Yes"),"Yes","No")
G2:G6G2=CONCAT(B2:D2)
 
Upvote 1
Solution
Thanks Peter, that makes sense. I have a follow-up question, in Post #3 why does that formula appear to work only for the first record?
 
Upvote 0
... in Post #3 why does that formula appear to work only for the first record?
Because in that formula, LOOKUP is looking for numbers and if there are multiple numbers, it expects them to be in ascending order, If not, results can be unpredictable. See the "Important" section under "Syntax" in the LOOKUP Help

In your row 3 the formula is
=LOOKUP(1,1*(B3:D3<>""),B3:D3)
=LOOKUP(1,1*{True, False, False},B3:D3)
=LOOKUP(1,{1,0,0},B3:D3)
Those numbers are not in ascending order so you are subject to the "unpredictable results".

The equivalent formula suggested in post #2 is
=LOOKUP(1,1/(B3:D3<>""),B3:D3)
=LOOKUP(1,1/{True, False, False},B3:D3)
=LOOKUP(1,{1,{1,#DIV/0!,#DIV/0!},B3:D3)
Here there is only one number so the numbers are in ascending order and so the formula works.
 
Upvote 0
Because in that formula, LOOKUP is looking for numbers and if there are multiple numbers, it expects them to be in ascending order, If not, results can be unpredictable. See the "Important" section under "Syntax" in the LOOKUP Help

In your row 3 the formula is
=LOOKUP(1,1*(B3:D3<>""),B3:D3)
=LOOKUP(1,1*{True, False, False},B3:D3)
=LOOKUP(1,{1,0,0},B3:D3)
Those numbers are not in ascending order so you are subject to the "unpredictable results".

The equivalent formula suggested in post #2 is
=LOOKUP(1,1/(B3:D3<>""),B3:D3)
=LOOKUP(1,1/{True, False, False},B3:D3)
=LOOKUP(1,{1,{1,#DIV/0!,#DIV/0!},B3:D3)
Here there is only one number so the numbers are in ascending order and so the formula works.
Thank you for the explanation, it helps to solidify the concept. It seems a powerful formula and is so versatile.
 
Upvote 0

Forum statistics

Threads
1,215,420
Messages
6,124,803
Members
449,190
Latest member
cindykay

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