+ Reply to Thread
Results 1 to 6 of 6

Sum based conditional sorting

  1. #1
    Registered User
    Join Date
    05-22-2014
    Posts
    1

    Sum based conditional sorting

    Hello,

    I can't seem to find an answer, but it could be that I'm asking the wrong questions.

    I have some data with various items that have a cost, and a numeric value. What I'm trying to do is extract a list of items to buy up to a set limit that will produce the maximum combined value. I've managed to get as far as sorting the items based on value/cost, and stopping the list when I can't afford the next item(I left that out for now for clarity), but I can't seem to figure out how to continue past that to the next item I could still afford?

    For example in the attached you will see that while I can't afford Item I, I should still be able to buy Item B.

    Would someone please help point me in the right direction?

    Thanks,
    B
    Attached Files Attached Files

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Sum based conditional sorting

    Here is a solution that uses Solver. Solver is an add-in. Do a web search for your version of Excel to see how to add it in.

    The issue with solver is to set up the problem. In this case I added two extra columns: Buy and Value. Buy has no formulas, Solver will fill this in. Value has the formula =B2*E2. So if B2 is zero then E2 is zero and if B2 is 1 then E2 is whatever B2 is.

    The target cell is F23 and it has the formula: =SUM(F2:F20)

    We are now ready for solver.

    We want the objective Cell (F23) to be equal to 67.

    By changing the cells in the ranage E2:E20 (Buy) - but these cells need constraining otherwise solver might want to buy more than one item or it might want to buy fractional items. So our constants are:

    E2:E20 <=1 and E2:E20 >= 0 - this means that the value has to be between 0 and 1. However, this is not enough since there are an infinite number of values between zero and one. So we also add the constrain that it must also be an integer. Given these constraints, the only possible values are zero and one.

    Click on the Solve button and solver will put a one or zero in the Buy column. Select the rows with the ones. Note that this may be only one of multiple possible solutions.

    On Sheet 2, I solved a slightly different problem in case it is the one you are actually trying to solve. I wanted to maximize the Value / Cost. So I set up a new target in Cell G23, and this time an additional constraint is that F23 = 67.
    Attached Images Attached Images
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Sum based conditional sorting

    It is possible to replace the 3 constraint for the range E2:E20 with only one constraint i.e.

    Please Login or Register  to view this content.
    Alf

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Sum based conditional sorting

    I decided to give it a try, but got an error stating that objective cells must be formulas.

  5. #5
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Sum based conditional sorting

    Strange, could you please test uploaded file and see if this work for you.

    Alf

    Ps When I uploaded the file for testing, objective cell was set to H13 or something like that but not to F23 as it should be. This would give the error you got when testing.
    Attached Files Attached Files
    Last edited by Alf; 12-14-2018 at 11:10 AM.

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Sum based conditional sorting

    I have two solver problems, one on sheet1 and the other on sheet2. That might be the issue.

+ 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. Conditional sorting problem
    By ronbrockbank in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-10-2014, 09:39 PM
  2. [SOLVED] Conditional Sorting
    By djh30 in forum Excel General
    Replies: 2
    Last Post: 07-08-2013, 01:23 PM
  3. Sorting with conditional formatting
    By skip2mylew in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-06-2013, 02:12 PM
  4. Copying specific cell based on two parameters and then sorting based on one parameter
    By buntalan80 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2012, 02:27 AM
  5. conditional sorting
    By Ahmad1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-24-2011, 07:04 AM
  6. Sorting and Delete rows meeting criteria based on sorting criteria
    By ron2k_1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-10-2011, 02:40 PM
  7. Conditional sorting
    By Psyke45 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-24-2007, 10:51 AM
  8. [SOLVED] Conditional Sorting
    By Rob in forum Excel General
    Replies: 1
    Last Post: 09-16-2005, 09:05 PM

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