Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

VLOOKUP from the top this time!

Has anyone got a clever solution for returning the first instance of a match to VLOOKUP rather than the last? Here's my issue:


DateOther Data
1/12/12Choir One
1/12/12Choir Two
1/19/12Choir One
1/19/12Choir Two


Every VLOOKUP scheme I can think of for, say, the instances in January 12 returns only info for Choir Two--not Choir One. I need it to start returning info from the TOP of the data subset instatiated by VLOOKUP (I know it really doesn't pull a full subset, but it does infer one--and then picks the BOTTOM instance).


Any clever ideas?

Macbook 2.13 GHz, 2GB SDRAM, Mac OS X (10.6.8)

Posted on Jan 27, 2012 8:35 PM

Reply
6 replies

Jan 28, 2012 12:37 AM in response to macmikey

Hi Mikey,


You may infer that VLOOKUP will 'pull a full subset', but VLOOKUP does not imply that it will do so (and is incapable of inferring anything). My own inference would be that since VLOOKUP is going to return a value to a single cell, it will return only a single value, and that value will be the one corresponding to the first instance of the search value that is found.


"First" depends on direction of search For LOOKUP, and for VLOOKUP with a 'close-match' that direction is from bottom to top of the search-range. Ronnie's experience has determined that an 'exact-match' setting appears to reverse the direction of search appears true in my brief tests, so using that setting would appear to match your desire regarding defining 'first' to mean 'instance closest to row 1.'


Another choice would be to use MATCH and OFFSET in place of VLOOKUP. MATCH appears to also change its direction of search with changes in the final argument, match-type, as can be seen in the results below. The formulas in Summary::B and C, and in Summary::D, E and F are the same except for the match-type set in the VLOOKUP or MATCH function (indicated by the number at the end of the column label).

User uploaded file


Summary::B2: =VLOOKUP($A2,Data :: $A:$B,2,)

(omitted=TRUE—close-match, shown in label as "1", FALSE—exact-match, shown in label as "0")

Summary::D2: =OFFSET(Data::$A$1,MATCH($A,Data :: $A,1)-1,1)


But your post implies that a single instance is not what you want to return in your summary table. Perhaps a more complete specification of the results you are looking for would help determin a solution to the actual issue.


Regards,

Barry


PS: "instatiated"? Mistyped? What word was intended?

Jan 28, 2012 5:35 PM in response to Barry

Hi Mikey,


You may infer that VLOOKUP will 'pull a full subset', but VLOOKUP does not imply that it will do so (and is incapable of inferring anything). My own inference would be that since VLOOKUP is going to return a value to a single cell, it will return only a single value, and that value will be the one corresponding to the first instance of the search value that is found.

Barry, I stand corrected. I should have said that I inferred the existence of a full subset, but not knowing the internal scheme for how Numbers finds data in a table, it is not unreasonable to suppose that there is always an implication (not inferrence, wrong choice of words) of a full subset, even if that full subset is one item (or record in this instance).


Your inference seems reasonable, or at least consistent with my experience. I just want to know why Numbers appears to be VLOOKing from the bottom up, and if there's an elegant (or even existent) way to subvert this.


"First" depends on direction of search For LOOKUP, and for VLOOKUP with a 'close-match' that direction is from bottom to top of the search-range. Ronnie's experience has determined that an 'exact-match' setting appears to reverse the direction of search appears true in my brief tests, so using that setting would appear to match your desire regarding defining 'first' to mean 'instance closest to row 1.'

Yes, this issue of direction is my point of concern. Why from the bottom to the top? Perhaps it was an arbitrary choice on the part of the programmers, perhaps there is some logical reasoning or protocol that all spreadsheet or database apps follow that I"m just not privy to. I thought briefly of the 'exact-match' setting, but couldn't deduce why that would return any different result. Seems it might have to do with some sorting factor in a field NOT involved in the VLOOKUP, though I'm not sure I'm mentally ready to tackle that possibility... 😊

Another choice would be to use MATCH and OFFSET in place of VLOOKUP. MATCH appears to also change its direction of search with changes in the final argument, match-type, as can be seen in the results below. The formulas in Summary::B and C, and in Summary::D, E and F are the same except for the match-type set in the VLOOKUP or MATCH function (indicated by the number at the end of the column label).

User uploaded file


Summary::B2: =VLOOKUP($A2,Data :: $A:$B,2,)

(omitted=TRUE—close-match, shown in label as "1", FALSE—exact-match, shown in label as "0")

This looks promising. I may experiment with this.

Summary::D2: =OFFSET(Data::$A$1,MATCH($A,Data :: $A,1)-1,1)


But your post implies that a single instance is not what you want to return in your summary table. Perhaps a more complete specification of the results you are looking for would help determin a solution to the actual issue.


Regards,

Barry

Actually, it is a single instance for each date. Here's my scenario:


My church has two children's choirs (differentiating on age/development). I'm producing a "homebrew" curriculum for teaching music to these kids, and I'm using a lot of the same educational assets (though using them differently to respect the age/development distictions). I was basically creating an overview table that had two rows for each date: one for one group, the next for the other group. Admittedly, the more correct method would have been to use one row for both groups, and just distinguish the data pulled in my report tables on another sheet, but I was hoping to be clever and not have fool with a table that would've needed three monitors to display the whole record at once.


Anyway, this isn't the first time I've had this crisis. I have another table in a different spreadsheet that is having "dating problems," so your suggestions here are making me think of looking at that monster again...

PS: "instatiated"? Mistyped? What word was intended?

How embarrassing. I can't even spell a silly word like "instantiated" correctly. Either that, or I couldn't spell correctly that I wasn't hungry (insatiated). I don't know, I apparently wasn't communicating very well on a number of points. It was pretty late last night... 😁

Jan 28, 2012 6:35 PM in response to macmikey

Why VLOOKUP and LOOKUP search from bottom to top is a mystery to me as well. I was sure I had read the description in the documentation somewhere, but a search for that while writing the post above was unsuccessful. It's posible I read the information in another post here or elsewhere. I can't recall anything addressing the Why question, though.


Ronnie's discovery of the reversal in apparent search direction when VLOOKUP searches for an exact-match was also a surprise to me. I wonder if that piece of the puzzle might be useful in your case where you are looking for two rows with the same date. The match-type argument in VLOOKUP could be made to alternate from row to row is set by a pair of functions:


=VLOOKUP($A2,Data :: $A:$B,2,ISODD(ROW()))

User uploaded file

Formula above is in all cells (except the header cell) in Summary::B

Error triangles are 'couldn't find' errors due to the empty cells in column A.


Might fit your scenario better.


Anyway, this isn't the first time I've had this crisis. I have another table in a different spreadsheet that is having "dating problems," so your suggestions here are making me think of looking at that monster again...


Good. Always nice to see a post has been useful beyond the current issue.

PS: "instatiated"? Mistyped? What word was intended?

How embarrassing. I can't even spell a silly word like "instantiated" correctly. Either that, or I couldn't spell correctly that I wasn't hungry (insatiated). I don't know, I apparently wasn't communicating very well on a number of points. It was pretty late last night... 😁


Been then, done that. 😉


Regards,

Barry

Jan 28, 2012 6:45 PM in response to macmikey

Relying on an undocumented feature is risky. The undocumented feature in this case is that an exact match appears to start the search from the top.


A more difficult method but one that does not rely on the direction of search is as follows:


Column A is your dates

Cell B2 =DATEVALUE(A)&COUNTIF($A$2:A2,A)

Fill down from B2 to complete column B

Column C = your "other data" column

The search =VLOOKUP(DATE(2012,1,12)&1,B:C,2)


Hide column B after setting everything up.


What it does is create in column B a string that is the date + a number indicating how many times that particular date has occurred so far. First occurrence will be a 1, second will be a 2, etc.


I used DATEVALUE in the column B formula so that it would ensure the proper format of the date when converted to a string. The date in Column A can be formatted some other way without affecting the results. The COUNTIF doesn't care how the date in column A is formatted, you can have one row as Jan 12, 2012 and another as 12-Jan-2012, they are equivalent.


You can also search for other occurrences of the same date, if you have a need to.


User uploaded file

Jan 28, 2012 7:40 PM in response to Badunit

Badunit writes:


"Relying on an undocumented feature is risky. The undocumented feature in this case is that an exact match appears to start the search from the top."


True, but in this case there may also be risk in 'relying on a documented feature'.


Consider the results in the last three columns of my previous post (copied below), where the difference in the MATCH function was in the "match-type" argument, in the light of this statement from the iWork Formulas and Functions User Guide article on MATCH (emphasis added):


"Cell numbering starts with 1 at the top or left cell for vertical and horizontal ranges,

respectively. Searches are performed top-to-bottom or left-to-right."


User uploaded file


That said, your use on an index column is probably the right direction in which to head.


Regards,

Barry

VLOOKUP from the top this time!

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.