+ Reply to Thread
Results 1 to 14 of 14

Summing Largest 50 values based on criteria

  1. #1
    Registered User
    Join Date
    05-08-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    14

    Summing Largest 50 values based on criteria

    Hello Hello.

    I have been working on this for 2 days and it's now time for more brains:

    I have an excel sheet of 8000 products (rows) from a supermarket. Column A are product names (The Economist, New York Times, Snickers, Time Magazine, etc) Column B has each product broken down by % of category sales (the economist is 3.9% of magazine sales, People is 2.9% of magazine sales, etc) and Column C is the category (Newspapers, magazines, candy, beverage, etc). I'm attempting to make a separate chart that sums the percent of sales of:

    the top 5 highest grossing magazines (I want to know the top 5 magazines represent __% of my total magazine sales)
    the top 10 highest grossing magazines
    the top 15 highest grossing magazines
    all the way up to the top 50 magazines

    I'll be doing this for about 20 different categories, and I'm hoping some simple formulas would do the trick. My problem is (well, at least one of my problems!) that I don't know how to combine a sumif (or sumifs) function while also plugging in the criteria of adding up just the top 5 (or top 50) highest values (percentages) of ONLY magazines (and then ONLY Newspapers, etc). Or, perhaps I shouldn't be trying to combine these formulas. Also, this worksheet will constantly be sorted in different ways, so the formulas have to be able to handle unsorted columns. Any ideas????

    Many thanks!

    ~ Scooby

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,336

    Re: Summing Largest 50 values based on criteria

    Maybe, array formula:

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    etc., all committed wit Ctrl-Shift-Enter rather than just Enter.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor Cerbera's Avatar
    Join Date
    07-06-2010
    Location
    Rotorua, New Zealand
    MS-Off Ver
    Excel 2007, 2013, 2016 & 365
    Posts
    137

    Re: Summing Largest 50 values based on criteria

    I thought you could add a "rank" column using formula: =COUNTIFS(C:C,C2,B:B,">"&B2)+1 copying down from D2

    Then you could have a sumifs formula with the criteria in two cells or hard coded.

    See the attached spreadsheet. shop items.xlsx

  4. #4
    Registered User
    Join Date
    05-08-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Summing Largest 50 values based on criteria

    Hello TMS,

    Thanks for your help.
    If I'm understanding this right, Your formula will look up the Top 5 from the entire Column A, however, I'm looking for the Top 5 from Column B, and ONLY from the category of magazines.

    Thanks!

  5. #5
    Registered User
    Join Date
    05-08-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Summing Largest 50 values based on criteria

    Cerbera, that's more of what I'm looking for. Thanks. Is there a way to do this without adding a column?

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Summing Largest 50 values based on criteria

    Try something like this:

    Data Range
    A
    B
    C
    D
    E
    F
    1
    Category
    Sales
    ------
    Category
    Top N
    Total
    2
    Candy
    95
    Candy
    3
    240
    3
    Candy
    79
    4
    Candy
    66
    5
    Candy
    21
    6
    Candy
    18
    7
    Candy
    3
    8
    Fruit
    98
    9
    Fruit
    81
    10
    Fruit
    52
    11
    Fruit
    31
    12
    Fruit
    20
    13
    Vegetable
    48
    14
    Vegetable
    17
    15
    Vegetable
    11
    16
    Vegetable
    11
    17
    Vegetable
    9
    18
    Wine
    72
    19
    Wine
    62
    20
    Wine
    62


    Enter the top N number in E2.

    Then, this array formula** in F2:

    =SUM(LARGE(IF(A2:A20=D2,B2:B20),ROW(INDIRECT("1:"&E2))))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  7. #7
    Registered User
    Join Date
    05-08-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Summing Largest 50 values based on criteria

    Mr. Valko, thanks! I'll give this a go soon. I already implemented Cerbera's suggestion and added an extra few columns as helper columns and this works wonderfully. However, I ran into a snag:

    I'm looking for the top items that scan through our registers. Sometimes, a barcode isn't in our system yet and the price needs to be manually entered at the register and put into a general category. For manually inputted candy at the register, I've labelled it *CANDY in our register system. Sometimes, this "item" shows up as a top seller, even though it represents many different items. And sometimes, it shows up as the second best selling item. I'd like to disregard this "item" in my formula.

    Here is my formula:

    =SUMIFS($M$28:$M$7000,$T$28:$T$7000,AC$3,$Y$28:$Y$7000,"<="&$AA5)

    Column M is % of Sales I'm summing
    Column T is the Category Number (each number represents a Category, for example: "Regular Candy" is Category 25
    AC3 is 25 (for "Regular Candy")
    Column Y is my helper column with Cerbera's COUNTIFS formula. Here is the formula taken from *CANDY:

    =COUNTIFS($T$28:$T$7000,$T478,$M$28:$M$7000,">"&$M478)+1

    The names of items are in Column F. Basically, what can I include in my SUMIFS formula to make it disregard an asterisk (*) at the very beginning of words from Column F and still sum the top 5 (or top 10, etc)? The asterisk is always the first character. Or maybe there's a better way??

    My apologies about all this! I feel like there's always exceptions to rules and I need all the exceptions built into the formulas and it drives me mad!

    Many Many Many Thanks. This forum has been extremely useful and this is my first post. I'm sorry I waited so long to do so!

    ~ Scooby

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Summing Largest 50 values based on criteria

    In both the SUMIFS/COUNTIFS functions the * asterisk is evaluated as a wildcard character.

    Can you post a SMALL sample file and show us what result you expect?

    20 rows and 2 or 3 columns worth of data is plenty. Remember, it's a SAMPLE file!

  9. #9
    Registered User
    Join Date
    05-08-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Summing Largest 50 values based on criteria

    I probably should have attached this at the beginning!


    Thank You!
    Attached Files Attached Files

  10. #10
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Summing Largest 50 values based on criteria

    In the file you have the category of Regular Candy with a category number of 25. There are no category numbers 25 in the data section. I assume that 25 is supposed to be 3?

    Also, can you change the category to just Candy?

    If there are not N instances of the category what should happen? For example, you want the top 10 sum for Newspapers but there are only 7 instances of the newspaper category.

  11. #11
    Registered User
    Join Date
    05-08-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Summing Largest 50 values based on criteria

    Hello. I think I got it:

    I used Cerbera's method, however I turned the COUNTIFS statement into an IF statement. Let's say the product names are in column A and since the items I didn't want in my calculations all contained an asterisk as the first character, I used: IF(LEFT(A1,1)<>"*",(COUNTIFS(.....cerbera's formula.....),9999) which puts this product at the bottom of the helper column's category.

    I appreciate all the help. You guys are the best!

    Much appreciated,

    ~ Scooby

  12. #12
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Summing Largest 50 values based on criteria

    Good deal. Thanks for the feedback!

    If your question has been solved please mark the thread as being solved.

    In the menu bar above the very first post select Thread Tools, then select Mark this thread as solved.

  13. #13
    Registered User
    Join Date
    05-08-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Summing Largest 50 values based on criteria

    Done and Done!

    You guys rock. I'll be back for more soon.......

    (this forum is slightly addicting.)

  14. #14
    Forum Contributor Cerbera's Avatar
    Join Date
    07-06-2010
    Location
    Rotorua, New Zealand
    MS-Off Ver
    Excel 2007, 2013, 2016 & 365
    Posts
    137

    Re: Summing Largest 50 values based on criteria

    Hi Scooby, glad you get resolution to the problem.

    If you feel that our input was useful can you click on the "add reputation" button below our details in the posts? I really need it as I'm trying to build some! Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Summing values based on criteria (SUMIF issues)
    By notsamsnead in forum Excel General
    Replies: 4
    Last Post: 08-11-2014, 09:03 PM
  2. Summing Values in column based upon multiple criteria
    By shantanuk in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-21-2012, 09:29 AM
  3. Summing values based on two criteria
    By smartguy in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 03-16-2007, 04:46 PM
  4. Summing Values Based on Text Criteria
    By ExcelTip in forum Tips and Tutorials
    Replies: 4
    Last Post: 11-02-2005, 10:58 PM
  5. Summing the N Largest Values in a Range
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 08-28-2005, 11:18 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1