Forum

Notifications
Clear all

VLookup query

6 Posts
3 Users
0 Reactions
115 Views
(@steeley)
Posts: 4
Active Member
Topic starter
 

I have a table in the following format

vlookup.jpg

I want to run a formula/query in column D to look in Column C and find the Item # in Column A matching it, and copy the text in column B of that Item #'s row into Column D of the searching row, otherwise leave it blank.  The result would be...

vlookup2.jpg

I'm not constrained by which column the formula/query runs/executes in (it could be E or any other unused column), so long as the result ends up in Column D (in this example).

Why? I'm porting old DB3 data into a sql DB format for use in a php-based program using excel as the "middleware" (actually, I'm the middleware, excel is the tool). The actual table I'm working with is closer to 8000 rows, and, for example, row 5823 column C could well reference item # 2. 

This is just one small part of the porting transformation process, and actually, the last one I have to complete, before I test upload. Alas, my head exploded on this one.. 

(And if this works, I have a 90,000 row table to tackle next, thank God for "fill down"..)

Disclaimer: I'm retired, been quite a few years since I've used excel, and this is a non-profit exercise in every sense of the phrase.

 
Posted : 17/04/2020 10:16 pm
(@steeley)
Posts: 4
Active Member
Topic starter
 

There were a couple of copy errors in the original vlookup2.jpg..

This is the corrected result

vlookup2-3.jpg

 

(Now you know why I want to "script" this...)

 
Posted : 17/04/2020 10:29 pm
Anders Sehlstedt
(@sehlsan)
Posts: 968
Prominent Member
 

Hello,

As you have posted this in the Power Query section, do you want a PQ solution or do you want a standard Excel formula using VLOOKUP?

The Excel formula solution. Write in cell D2 and drag down.
=IFNA(VLOOKUP($C2,$A$2:$B$11,2,0),””)

I can’t give you the PQ solution now as I am using a tablet.

Br,
Anders

 
Posted : 18/04/2020 11:59 am
(@steeley)
Posts: 4
Active Member
Topic starter
 

Thanks for the reply, Anders!

Actually, at this point all I want is a solution that works.. whatever does the trick! (I didn't think a standard excel formula would work, but if your suggested solution does, I'm more than good with that..).

OK, I see what confused me with this originally... adding a dollar sign in front of the column alphabet (C in this example), it locks the column only. This means that if I drag the formula containing $C2, the column won't change, but the row will.

To make sure I understand the formula =IFNA(VLOOKUP($C2,$A$2:$B$11,2,0),””),  since the actual table I'm working with is far more extensive than this simple example, I believe the VLOOKUP part of the formula is saying:

lookup data "in column C of this row, for a match in the table A2 to B11 (column 1 of the defined table is default lookup), and copy column 2 data (of the matched row in the defined table). The "0" will force excel to return an N/A if there is nothing to match in Column C, correct?

If that is correct, then IFNA will return null "" if there is no match (i.e. column C has no lookup value, or there is no matching value in the specified range, and the vlookup result is "N/A").

Have I got that right?

-Dan

 
Posted : 18/04/2020 3:52 pm
(@mynda)
Posts: 4761
Member Admin
 

Hi Dan,

Yes, you've correctly understood Anders solution.

Mynda

 
Posted : 18/04/2020 7:20 pm
(@steeley)
Posts: 4
Active Member
Topic starter
 

Thanks Mynda, and thanks again Anders, and finally, thanks to the administrator for moving this to the proper topic! Off to put excel to work..

 
Posted : 19/04/2020 9:44 am
Share: