MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Nov 30th, 2008, 02:46 AM   #1
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 321
Default Large Lookup Problem w Duplicates

Dear Smartest Excelers In The World,

In cells A1: E7, I have this data set:

YEAR MONTH RESTAURANT PRODUCTS SALES
2008 October McDonald's Big Mac $100,000.00
2008 October Burger King Double Whopper $1,500.00
2008 October McDonald's Triple Whopper $100,000.00
2008 November McDonald's Filet O Fish $20,000.00
2008 October McDonald's Tofu $55,000.00
2008 October McDonald's Apples $99,855.00

Using a formula, I want to return the three largest values and the associated PRODUCTS based on these three criteria:
YEAR = 2008
MONTH = October
RESTAURANT = McDonald's

The resultant data set should be:

SALES PRODUCTS
$100,000.00 Big Mac
$100,000.00 Triple Whopper
$99,855.00 Apples

What formula would I use to return the values $100,000, $100,000, and $99,885 for the Sales column? And what formula would I use to return Big Mac, Triple Whopper, and Apples for the PRODUCTS column?

Any ideas, Excel formula Masters?
__________________
Sincerely, Mike Gel Girvin
mgirvin is offline   Reply With Quote
Old Nov 30th, 2008, 03:22 AM   #2
gauntletxg
 
Join Date: Jul 2008
Location: Cleveland, OH
Posts: 596
Default Re: Large Lookup Problem w Duplicates

Have you tried using AutoFilter?
gauntletxg is offline   Reply With Quote
Old Nov 30th, 2008, 06:52 AM   #3
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 40,228
Default Re: Large Lookup Problem w Duplicates

If you insist on or desire a formula system...



YEARMONTHRESTAURANTPRODUCTSALESYEAR2008
2008OctoberMcDonald'sBig Mac$100,000.00 MONTHOctober
2008OctoberBurger KingDouble Whopper$1,500.00 RESTAURANTMcDonald's
2008OctoberMcDonald'sTriple Whopper$100,000.00 Top3
2008NovemberMcDonald'sFilet O Fish$20,000.00 Largest Value$99,885.00
2008OctoberMcDonald'sTofu$55,000.00 Count3
2008OctoberMcDonald'sApples$99,885.00 SALESPRODUCT
$100,000.00 Big Mac
$100,000.00 Triple Whopper
$99,885.00 Apples


H1:H4 houses the criteria/conditions.

H5:

Control+shift+enter, not just enter...

=LARGE(IF($A$2:$A$7=H1,IF($B$2:$B$7=H2,IF($C$2:$C$7=H3,$E$2:$E$7))),H4)

H6:

=SUMPRODUCT(--($A$2:$A$7=H1),--($B$2:$B$7=H2),--($C$2:$C$7=H3),--($E$2:$E$7>=H5))

G8:

Control+shift+enter, not just enter...
Code:
=IF(ROWS($G$8:G8)<=H$6,
  LARGE(IF($A$2:$A$7=H$1,IF($B$2:$B$7=H$2,IF($C$2:$C$7=H$3,$E$2:$E$7))),
    ROWS($G$8:G8)),"")
and copy down.

H8:

Control+shift+enter, not just enter...
Code:
 
=IF(ISNUMBER(G8),INDEX($D$2:$D$7,SMALL(
    IF($A$2:$A$7=H$1,IF($B$2:$B$7=H$2,IF($C$2:$C$7=H$3,IF($E$2:$E$7=$G8,
      ROW($D$2:$D$7)-ROW($D$2)+1)))),COUNTIF($G$8:G8,G8))),"")
and copy down.
Aladin Akyurek is offline   Reply With Quote
Old Nov 30th, 2008, 08:32 AM   #4
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 321
Default Re: Large Lookup Problem w Duplicates

Dear gauntletxg,

Thanks for the tip! Yes, Auto Filter would be so simple, but what I was after was a dynamic formula that sat on a sheet and looked at the Table on another sheet. And the Table will get data added to it periodically and so the formula "always update" solution was preferable.
__________________
Sincerely, Mike Gel Girvin
mgirvin is offline   Reply With Quote
Old Nov 30th, 2008, 08:40 AM   #5
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 321
Default Re: Large Lookup Problem w Duplicates

Dear Aladin Akyurek,

You are like a super hero that flies in and saves the day!

The most amazing part of your formula was the fourth IF that asked the sales range if it was equal to the value one cell to the left, and then you SMALLed with a COUNTIF!

So elegant and efficient!

Thanks for putting up with my desire for a formula when Auto Filter would be so easy!

You and many others at this Message Board really make the world a better place with your amazing Excel EXCELlence!!
__________________
Sincerely, Mike Gel Girvin
mgirvin is offline   Reply With Quote
Old Dec 11th, 2008, 11:02 PM   #6
sitngo
 
Join Date: Nov 2008
Posts: 5
Default Re: Large Lookup Problem w Duplicates

hi guys,

Having just looked through the steps of this formula, I'm having trouble understanding what the 'small' function does (why aren't we looking for the large), as well as the Row - Row part of the function. I know it's a lot of work, but i'd like to understand the steps of this formula, please help!
sitngo is offline   Reply With Quote
Old Dec 12th, 2008, 12:30 AM   #7
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 321
Default Re: Large Lookup Problem w Duplicates

Dear sitngo,

The LARGE is used to find the values. The LARGE function can deal with duplicates. However, the formula that retrieves the restaurants needs a way to deal with duplicates. The SMALL and COUNTIF functions help to deal with duplicate values. After the array part of the formula delivers an array of FALSEs and values to the SMALL function, the SMALL and COUNTIF functions will retrieve the first duplicate when the COUNTIF is 1 and the second duplicate when the COUNTIF is 2.

When you type the formulas and this example into your spreadsheet, type a duplicate value in, and then run the formula evaluator to see how it is helping with duplicates.

I hope that helps.
__________________
Sincerely, Mike Gel Girvin
mgirvin is offline   Reply With Quote
Old Dec 12th, 2008, 06:11 AM   #8
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 40,228
Default Re: Large Lookup Problem w Duplicates

Quote:
Originally Posted by sitngo View Post
hi guys,

Having just looked through the steps of this formula, I'm having trouble understanding what the 'small' function does (why aren't we looking for the large), as well as the Row - Row part of the function. I know it's a lot of work, but i'd like to understand the steps of this formula, please help!
I guess you mean SMALL that appears in the last formula... You can substitute LARGE for SMALL in that formula. The substitution will affect the order of items in the result, not the content.

SMALL works on the result array that IF delivers. This result array consists of a relevant set of ascending row numbers, adjusted to start at 1...

In

ROW($D$2:$D$7)-ROW($D$2)+1

ROW($D$2:$D$7) would yield: 2,3,4,5,6,7

ROW($D$2) would yield 2

Substraction would result: 0,1,2,3,4,5

Addition (+1) would then give: 1,2,3,4,5,6

Depending on the test condition in IF some of the numbers in the result set will be replaced with FALSE. SMALL will act on the surviving numbers and feed INDEX for retrieval.
Aladin Akyurek is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 05:09 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes