Thursday, June 21, 2007

Two Field Lookup with Excel VLookup

I'm not a big fan of using Excel as a database application.  It wasn't designed to be one.  But some of the functions in Excel allow a lookup (or query, if you will) which leads some people to use it as a database.

The VLookup function encourages this thinking.  You pass in a lookup value, a data range, and the column that contains the value you want to retrieve from the data range.  There are some assumptions with the VLookup function. 

  1. Your data must have the Primary Key or lookup column as the first column in the data range. 
  2. The data must be sorted Ascending by the lookup column (first column)
  3. The lookup column must contain single field, unique values

The VLookup has an optional parameter that lets you specify if you want an exact match or if you want Excel to choose the nearest value.

The problem I ran in to was that I needed to lookup a value based on two pieces of data.  The function is designed to only lookup based on a single value.

SOLUTION:

My solution was to combine my two data fields into a single TEXT field and use that value as the lookup value.  For example, my data was organized by Product ID in Column A and a Date in Column B.  Column C held a quantity value that related to a specific product on a specific date.

I first inserted a column at Column A.  This placed my Product ID in Column B, my Date in Column C, and my Quantity in Column D.  In Column A, I entered a formula to calculate my lookup values.  The formula is as follows for cell A2:

=TEXT(B2,"00000") & TEXT(C2,"yymmdd")

This formula converts my Product ID (which is a number value) to text and fixes at 5 digits with leading zeros if necessary.  The formula then concatenates the Date value which is also converted to text in the format of year month day.  So for Product ID = 1 and Date = June 22, 2007 my formula would return 00001070622.  Copying this formula for all rows of data produces my lookup values.

Next the whole data range must be sorted by Column A (lookup values).  Now the data range has been prepped for a two field lookup.

Whenever I want to query for a Quantity of a specific Product on a specific date, I would use a formula such as this:

=VLOOKUP( {cell with lookup formula}, {data range}, 4, FALSE)

NOTE:  I tried to create and lookup formula inside the VLOOKUP function but Excel kept giving an error.  So I created a formula outside of my report area that created the lookup value I needed to reference.  I used this formula:

=TEXT({cell with Product ID I needed},"00000") & TEXT({cell with Date I needed},"yymmdd")

{data range} was the sheet and range (or could be named range) where my data table was in the workbook.

The 4 represents Column D where my Quantity data is.  The FALSE in the formula tells Excel to make an exact match.  I don't want to be returned an approximate value -- I want to know the VLookup found the actual quantity I'm searching.

8 comments:

Anonymous said...

Hi !.
You re, I guess , probably curious to know how one can reach 2000 per day of income .
There is no initial capital needed You may begin to get income with as small sum of money as 20-100 dollars.

AimTrust is what you thought of all the time
AimTrust represents an offshore structure with advanced asset management technologies in production and delivery of pipes for oil and gas.

It is based in Panama with structures around the world.
Do you want to become a happy investor?
That`s your chance That`s what you really need!

I`m happy and lucky, I started to take up real money with the help of this company,
and I invite you to do the same. It`s all about how to choose a correct companion who uses your savings in a right way - that`s it!.
I earn US$2,000 per day, and my first deposit was 1 grand only!
It`s easy to join , just click this link http://ravehimo.ibnsites.com/nigufaty.html
and lucky you`re! Let`s take this option together to feel the smell of real money

Anonymous said...

[u][b]Xrumer[/b][/u]

[b]Xrumer SEO Professionals

As Xrumer experts, we from been using [url=http://www.xrumer-seo.com]Xrumer[/url] fitted a sustained time now and grasp how to harness the enormous power of Xrumer and turn it into a Cash machine.

We also provender the cheapest prices on the market. Numberless competitors desire expect 2x or square 3x and a a pile of the continuously 5x what we charge you. But we maintain in providing gigantic service at a debilitated affordable rate. The whole incidental of purchasing Xrumer blasts is because it is a cheaper alternative to buying Xrumer. So we focusing to stifle that bit in rebuke and afford you with the cheapest rate possible.

Not only do we cause the greatest prices but our turnaround in the good old days b simultaneously payment your Xrumer posting is wonderful fast. We compel have your posting done to come you certain it.

We also produce you with a sated log of well-heeled posts on contrary forums. So that you can catch a glimpse of over the extent of yourself the power of Xrumer and how we have harnessed it to gain your site.[/b]


[b]Search Engine Optimization

Using Xrumer you can wish to distinguish thousands upon thousands of backlinks exchange for your site. Many of the forums that your Location you will be posted on oblige exalted PageRank. Having your tie-in on these sites can deep down expropriate found up some crown rank back links and really riding-boot your Alexa Rating and Google PageRank rating via the roof.

This is making your instal more and more popular. And with this increase in regard as grammatically as PageRank you can keep in view to witness your site really rank high-pitched in those Search Motor Results.
Conveyance

The amount of traffic that can be obtained nearby harnessing the power of Xrumer is enormous. You are publishing your site to tens of thousands of forums. With our higher packages you may regular be publishing your position to HUNDREDS of THOUSANDS of forums. Visualize 1 post on a stylish forum last will and testament by get 1000 or so views, with communicate 100 of those people visiting your site. These days create tens of thousands of posts on in demand forums all getting 1000 views each. Your see trade longing associate sometimes non-standard due to the roof.

These are all targeted visitors that are interested or bizarre nearly your site. Imagine how divers sales or leads you can fulfil with this considerable gang of targeted visitors. You are line for line stumbling upon a goldmine friendly to be picked and profited from.

Keep in mind, Traffic is Money.
[/b]

GET YOUR TWOPENNY BLAST TODAY:


http://www.xrumer-seo.com

Anonymous said...

Hello!
You may probably be very interested to know how one can manage to receive high yields on investments.
There is no initial capital needed.
You may commense earning with a sum that usually is spent
for daily food, that's 20-100 dollars.
I have been participating in one company's work for several years,
and I'll be glad to let you know my secrets at my blog.

Please visit my pages and send me private message to get the info.

P.S. I make 1000-2000 per day now.

http://theinvestblog.com [url=http://theinvestblog.com]Online Investment Blog[/url]

Anonymous said...

[B]NZBsRus.com[/B]
Lose Idle Downloads Using NZB Files You Can Hastily Find HD Movies, Console Games, Music, Software & Download Them @ Rapid Speeds

[URL=http://www.nzbsrus.com][B]Usenet Search[/B][/URL]

Anonymous said...

Emancipation Our Cloudy Prices at www.Pharmashack.com, The Unequalled [b][url=http://www.pharmashack.com]Online Chemist's workshop [/url][/b] To [url=http://www.pharmashack.com]Buy Viagra[/url] Online ! You Can also Admit Straight-faced Deals When You [url=http://www.pharmashack.com/en/item/cialis.html]Buy Cialis[/url] and When You You [url=http://www.pharmashack.com/en/item/levitra.html]Buy Levitra[/url] Online. We Also Delight a Earliest Generic [url=http://www.pharmashack.com/en/item/phentermine.html]Phentermine[/url] As a preservation to Your Nutriment ! We Pay-off up Cyclopean swig trade-mark [url=http://www.pharmashack.com/en/item/viagra.html]Viagra[/url] and Also [url=http://www.pharmashack.com/en/item/generic_viagra.html]Generic Viagra[/url] !

Anonymous said...

Infatuation casinos? into this up to the journal [url=http://www.realcazinoz.com]casino[/url] admonish and wing it denigrate online casino games like slots, blackjack, roulette, baccarat and more at www.realcazinoz.com .
you can also balk our additional [url=http://freecasinogames2010.webs.com]casino[/url] orientate at http://freecasinogames2010.webs.com and lower oneself attack realized incredibly remote !
another ancillary [url=http://www.ttittancasino.com]casino spiele[/url] purlieus is www.ttittancasino.com , because german gamblers, take woe of magnanimous online casino bonus.

Anonymous said...

Someone deleted several links from cobrashare and hotfile servers.

From now, we will use www.tinyurlalternative.com as our default [url=http://www.tinyurlalternative.com]url shortener[/url], so every link will be there and visible for everyone.

You can pick out from many great [url=http://kfc.ms]short url[/url] names like:

kfc.ms easysharelink.info jumpme.info megauploadlink.info megavideolink.info mygamelink.info myrapidsharelink.info mytorrentlink.info myurlshortener.com mywarezlink.info urlredirect.info urlshrinker.info weblinkshortener.com youtubelink.info and many others.

They maintain over 60 different available domains and the [url=http://myurlshortener.com]url shortener[/url] service work well for free without any registration needed.

So we assume it is good notion and suggest you to use [url=http://urlredirect.info]url redirect[/url] service too!

Thank you.

Anonymous said...

Hi everyone


Try http://www.BuySellDirect.net, they are the future of e-commerce; you will get a free ebay advance website to sell your products direct to consumers. You can also buy direct from the original producers or the owner of the products and really save your money.


Do your self a favorite buy using http://www.BuySellDirect.net FREE service to make a second income.

 
2007, Chase Computer Services.