SOLVED

XLOOKUP Strange Behaviour

%3CLINGO-SUB%20id%3D%22lingo-sub-2408314%22%20slang%3D%22en-US%22%3EXLOOKUP%20Strange%20Behaviour%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2408314%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20trying%20to%20use%20XLOOKUP%20function%20using%20an%20excel%20table%20where%20I%20make%20the%20search%2C%20which%20as%20the%20first%20column%20formatted%20as%20Text%20as%20it%20will%20acomodate%20data%20which%20needs%20to%20be%20formatted%20this%20way.%20The%20XLOOKUP%20uses%20a%20cell%20as%20input%20for%20the%20lookup%20value.%20Depending%20on%20the%20way%20this%20cell%20is%20formatted%20the%20XLOOKUP%20function%20behaves%20differently.%20If%20the%20input%20cell%20is%20formatted%20as%20General%2C%20everything%20works%20as%20it%20should.%20But%20if%20I%20format%20the%20cell%20as%20Text%20(because%20I%20need%20to%20input%20a%20numeric%20string%20with%20leading%20zeros%20as%20data)%2C%20then%20the%20XLOOKUP%20returns%20%23N%2FA...%26nbsp%3B%3CBR%20%2F%3EI've%20prepared%20a%20small%20Excel%20file%20to%20demonstrate%20the%20situation.%3CBR%20%2F%3ECould%20anyone%20help%20me%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2408314%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2408966%22%20slang%3D%22en-US%22%3ERe%3A%20XLOOKUP%20Strange%20Behaviour%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2408966%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1069397%22%20target%3D%22_blank%22%3E%40MrBig1964%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20is%20working%20now.%20I'm%20not%20sure%20but%20I%20think%20that%20you%20might%20have%20had%20an%20(invisible)%20character%20in%20at%20least%20one%20of%20the%20cells%20involved%20in%20the%20text%20version%20of%20the%20lookups.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOne%20of%20the%20biggest%20traps%2C%20and%20it%20messes%20people%20up%20all%20the%20time%2C%20is%20typing%20in%20text%2C%20say%2C%20as%26nbsp%3B%20%221%20%22%20--which%20to%20the%20human%20eye%20looks%20the%20same%20as%20%221%22...but%20isn't%20at%20all%20the%20same%2C%20and%20the%20computer%20doesn't%20see%20it%20as%20the%20same.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2409219%22%20slang%3D%22en-US%22%3ERe%3A%20XLOOKUP%20Strange%20Behaviour%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2409219%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F425987%22%20target%3D%22_blank%22%3E%40mathetes%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMany%20thanks%20for%20your%20help.%3C%2FP%3E%3CP%3EI've%20noticed%20that%20you%20inserted%20new%20values%20in%20the%20data%20column%20and%20that%20help%20me%20to%20find%20the%20problem.%3C%2FP%3E%3CP%3EI%20didn't%20have%20any%20space%20or%20anything%20else%20before.%20The%20problem%20is%20(perhaps)%20that%20if%20I%20change%20the%20format%20of%20the%20column%20keeping%20the%20old%20data%20there%2C%20it%20assumes%20the%20initial%20data%20%22type%22.%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20your%20file%20if%20you%3A%3C%2FP%3E%3COL%3E%3CLI%3EErase%20the%20content%20of%20the%20first%20column.%3C%2FLI%3E%3CLI%3EChange%20the%20column%20to%20data%20format%20%22Number%22.%3C%2FLI%3E%3CLI%3EReinsert%20a%20new%20set%20of%20data%20(i.e.%201%2C%202%2C%203).%3C%2FLI%3E%3CLI%3EReformat%20the%20column%20once%20again%20to%20data%20format%20%22Text%22%3C%2FLI%3E%3C%2FOL%3E%3CP%3EYou%20get%20the%20same%20problem%20as%20before.%3C%2FP%3E%3CP%3ESo%20my%20conclusion%20is%20that%20cannot%20insert%20data%20in%20the%20column%20before%20formating%20the%20column%20to%20the%20data%20type%20you%20want.%3C%2FP%3E%3CP%3ERegarding%20the%20INDIRECT%20function.%20Well...%20it%20was%20the%20only%20way%20I%20had%20to%20XLOOKUP%20accept%20a%20concatened%20string%20as%20a%20function%20parameter.%20In%20the%20work%20I%20am%20doing%2C%20I%20define%20dynamically%20the%20column%20where%20I%20want%20to%20get%20the%20returning%20data.%20That's%20the%20reason.%20I've%20tried%20to%20use%20a%20simple%20string%20concatenation%20(like%20i.e.%20%22Table1%5B%22%26amp%3BE5%26amp%3B%22%5D%22%20but%20that%20didn't%20result.%20Don't%20know%20why...%3C%2FP%3E%3CP%3EThanks%20once%20again.%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

I'm trying to use XLOOKUP function using an excel table where I make the search. This table as the first column formatted as Text as it will acomodate data that needs to be formatted this way. The XLOOKUP uses a cell as input for the lookup value. Depending on the way this cell is formatted the XLOOKUP function behaves differently. If the input cell is formatted as General, everything works as it should. But if I format the cell as Text (because I need to input a numeric string with leading zeros as data), then the XLOOKUP returns #N/A... 
I've prepared a small Excel file to demonstrate the situation.
Could anyone help me?

7 Replies

@MrBig1964 

 

It is working now. I'm not sure but I think that you might have had an (invisible) character in at least one of the cells involved in the text version of the lookups.

 

One of the biggest traps, and it messes people up all the time, is typing in text, say, as  "1 " --which to the human eye looks the same as "1"...but isn't at all the same, and the computer doesn't see it as the same.

 

I basically re-entered the texts in the table where you're performing the lookup.

 

By the way, for a demonstration file, this has some of the most elaborate functions--using INDIRECT, etc.--is all of that really necessary in whatever it is that you're creating?

 

@mathetes 

Many thanks for your help.

I've noticed that you inserted new values in the data column and that help me to find the problem.

I didn't have any space or anything else before. The problem is (perhaps) that if I change the format of the column keeping the old data there, it assumes the initial data "type". 

In your file if you:

  1. Erase the content of the first column.
  2. Change the column to data format "Number".
  3. Reinsert a new set of data (i.e. 1, 2, 3).
  4. Reformat the column once again to data format "Text"

You get the same problem as before.

So my conclusion is that cannot insert data in the column before formating the column to the data type you want.

Regarding the INDIRECT function. Well... it was the only way I had to XLOOKUP accept a concatened string as a function parameter. In the work I am doing, I define dynamically the column where I want to get the returning data. That's the reason. I've tried to use a simple string concatenation (like i.e. "Table1["&E5&"]" but that didn't result. Don't know why...

Thanks once again.

@MrBig1964 

Agreed.  The lookup array still comprised numbers despite being number-formatted as text.  Re-entering the numbers changed them to text and the XLOOKUP then works (the little green triangle warning the user of numbers held as text also appears at that point).

 

A non-volatile alternative to your use of INDIRECT would to use a further XLOOKUP to return the column to search,

= XLOOKUP(CodArt1,
  Table1[H1],
  XLOOKUP(E4,
    Table1[#Headers],
    Table1)
  )

 

@MrBig1964 

 

INDIRECT is a tricky function. Wonderful once you get it to work, but tricky. I think you might have the quotation marks in the wrong place, or too many. You'll figure it out.

 

Here's an example of one that I have that, once all is said and done, refers to a different tab, a tab that may or may not have a special character in it, and then a specific cell within that tab.

=INDIRECT($B8&IF($C8="","","_"&$C8)&"!"&J$1)

You'll notice that the cell references there do NOT have quotes around them. Let me break that down a bit (hoping it won't overwhelm with detail).

  • $B8 refers to a cell that contains text that, in many cases, is the name of the tab
    • There are times, however, when that name is repeated but with different extensions, SO..
    • ... $C8 refers to a cell that may or may not contain the rest of the tab's name; if it's blank, then my INDIRECT does not add anything to the text in $B8, but if there's content in $C8, then INDIRECT adds an underscore plus whatever content is in $C8.
    • So all of that is to create the correct Tab name
  • It then adds the exclamation point and yet another cell reference, J$1, which itself contains the cell reference desired on the tab, the name of which was created in those first components.

The result of all those concatenations will be something like this: =AAPL_CC!C3. That is to say, that INDIRECT (which appears a summary sheet in a workbook tracking investments) goes to an individual sheet where I track an investment in an Apple Covered Call, to retrieve the value in cell C3 of that sheet, and bring it back to a summary sheet tracking all of the investments in various companies. I copy that INDIRECT down a column so that it picks up different names of different equities, pointing to different sheets, but always bringing back cell C3 in each of those sheets.

 

P.S. Added after @Peter Bartholomew added his reference to volatility: I have quite a few of those INDIRECT functions in a 1.7 MB file, and it still performs all its recalculations in a split second. No noticeable delays.

@MrBig1964 

 

It was here in techcommunity that I learned what "volatile function" means. @Peter Bartholomew has given you a "non-volatile" alternative...basically a straight XLOOKUP...to perform your lookup. I just wanted to assure you that "volatile" in Excel terminology doesn't mean the same thing as having, say, a volatile business partner, one you never know how he/she is going to respond.

 

Volatile Excel functions end up taking more time because they recalculate every time--EVERY TIME--a calculation is performed, whether or not any of their references have changed. So in a really large spreadsheet, that can become a performance issue. But it's not as though sometimes they'll say 2+2=4, but other times 2+2 = 3.1416, or "who cares? what 2+2 equals?!"

http://www.decisionmodels.com/calcsecretsi.htm

 

best response confirmed by MrBig1964 (New Contributor)
Solution

@MrBig1964 

As a comment, if both lookup value and lookup column are texts, when this works

=XLOOKUP(
  CodArt3,
  CHAR(173)&Table3[H1],
  XLOOKUP(E26,Table3[#Headers],Table3)
)

Better

=XLOOKUP(
   ""&CodArt3,
   ""&Table3[H1],
   XLOOKUP(E26,Table3[#Headers],Table3)
)

which works for combination of texts and numbers.

Would it not be easiest to format the cell to show leading zeroes? And still be numeric?