Using Solver to Assign Items to Buckets

Share

Facebook
Twitter
LinkedIn

In April 2011, Mdsuhair asked a question at the Chandoo.org Forums

What formula can I use to divide a group of numbers into 2 groups so that the Sum of each of the 2 groups is as equal as possible?

This is a candidate for Solver.

This post will walk us through the solution to the problem using Solver. It uses Solver and screen shots from Excel 2007.

All versions of Excel have solver available. Users should note that the screen shots may not match your version although the functionality will, some of the functions appear in different locations in different versions of Solver.

What and Where Is Solver

What is Solver

Solver is an Excel add-in that can solve problems by enabling a Target cell to achieve some goal.

This goal may be to minimse, maximise, or achieve some target value.

It solves the problem by adjusting a number of input cells according to a set of criteria or constraints which are defined by the user.

Where is Solver

Solver is an Excel add-in supplied with Excel, but not enabled by default.

To enable solver

File, Excel Options, Add-ins, Manage Excel Add-ins, Select the Solver Add-in checkbox

Solver will now appear as a New Tab on the Data, Analysis Tab

Solver Example

This post is based around a worked example Solver Example File, the file is compatible with all versions of Excel.

Defining the Problem

Mdsuhair had a series of 8 Items each which had a value:

 

He wants to know which items should be combined so that the sum of the values of the items is nearly equal.

To do this we need to assign each item into a Bucket. Namely Bucket A and Bucket B.

We will put values of 1 into a Bucket for each Item to show that it is assigned to that Bucket and a value of 0 to show that the bucket is empty (In/Out) Value.

We can start by adding a Total Column, which counts items in Buckets A + Bucket B for each Item, It then totals the totals.

We also know that we need to work out the Value of each Item in each Bucket

We do this by multiplying the Items Value by the Buckets (In/Out) value

Finally we need to add up the values in each Bucket and work out the difference between them

Mdsuhair’s original problem was to minimise the difference between the sum of the values in the 2 buckets.

Now we can place values of 1 in the buckets manually and Excel will show us the value of each Bucket and the Difference between them in Cell G11.

I have applied some conditional formatting to show when a cell has a value > 0.

The problem is that there are 28 or 256 combinations of answers, and to test them all manually at 1 every 5 seconds would take 21.3 minutes, assuming we can keep up that pace and remember which was the best combination.

This is where solver comes to the fore.

Applying Solver

To apply solver we need to define a series of requirements, rules and constraints.

These requirements, rules and constraints guide solver and set limits which allow solver to quickly narrow in on the answer.

What are our rules

Our main requirement is to minimise the difference between the value of the 2 buckets.

The difference between the 2 buckets in our example is cell G11, the sum of Bucket 2 values minus the Sum of Bucket 1 values.

We want to have G11 as low as possible but greater than or equal to 0.

 

We also know that an item can only be in Bucket A or Bucket B, it can’t be in both and can’t be Broken apart.

That is 2 Constraints for each Item

Firstly The Total column must be equal to 1

Secondly the Buckets Values must be Integers

We also know that the Total Number of Items is 8, this is another constraint.

We will discuss how these constraints are used in the next section

The Solver Window

This section will explain the solver window and its use in defining the problem within solver.

A Blank Solver Window

A Filled Solver Window

Set Target Cell:

This is the Target cell which is the cell which you are trying to solve the problem for.

Our Target cell is G11, The difference between the 2 Buckets values

Equal To:

The Equal To: section defines what we want to do with our Target Cell.

We want to achieve the same value in each Bucket and so the difference between the Buckets will be 0.

It might sound strange but we don’t want to minimise that difference. A minimal value will be achieved when all the Items are placed in Bucket A, as our equation for G11 will then have 0 – Total which is –Total, which is more minimal than 0.

Another way to constrain this is to Change G11 to =Abs(G10-H10)

This allows us to use Min as an Equal To: Value

But for now we can just leave G11 as =G10-H10 and we will set the Equal To: section as 0.

By Changing Cells:

Changing Cells: refers to the cells which will be modified by Solver to try and solve the problem.

We want to let Solver change the number of items in each bucket, this is the range: $C$2:$D$9

Hint: You can try the Guess button next to the Range Reference and Solver will take a Guess at what cells the problem is dependent on.

Always check this if you use it, especially in complex models.

Subject to the Constraints:

Constraints are the rules which define the limits of the possible solutions to the problem

We will add several constraints for our rules:

1. The Total column must be equal to 1 for each Item

2. The Bucket Value must be an Integer

3. The total contents of the 2 buckets must be 8 items

4. You could add a further constraint that each Bucket should hold the same number of items

Hint: As a general Rule, Under Constrain rather than over constrain! You can always add more constraints later.

To do this we will use the Add Constraint Button

1. We need to add a constraint for each cell in the Range E2:E9 that it is only allowed to be = 1

This constraint must be applied for each cell in the range E2:E9

2. We need to add a constraint for each cell in the Range C2:D9 that it is only allowed to be an integer

This constraint must be applied for each cell in the range C2:D9

3. We need to add a constraint for the Total of the 2 Buckets, E10=8

You can Change or Delete Constraints if you make a mistake by selecting the appropriate constraint and using the Change or Delete Buttons

Save and Load Solves Parameters

Selecting the Options Button there is the Option to Save Model and Load Models.

Hint: The Save/Load Models has been shifted onto the main Solver dialog in Excel 2010.

Using the Save Model and Load Model options you can Save and the Load the Solver Parameters for your model. The Save Model saves the parameters in a Range of cells as shown below.

This allows an easy way to actually setup and/or change the solver parameters.

Hint: Setup one constraint using solver then Save the model. Edit the model on the worksheet and re-load the model as required.

Note: That the parameters although when saved show as True/False or Numbers are all Excel Equations, see above.

This means you can edit them to change the Constraints and Parameters as required and re-load them into solver.

I have included 3 sets of Parameters for our model.

These are:

  • Base Case – Forces bucket values to be equal, Allows uneven bucket counts
  • Equal Sized Buckets – Forces each bucket to contain the same number of items
  • Force an error – Which forces an error in the solver model

Load each model and try them at your leisure.

Running the Solver Model

Warning: Solver is a computationally complex add-in, so once your model is setup, Save your Workbook.

Prior to running the model there are a few parameters we should look at to ensure the model solves correctly.

On the main Solver window select the Options button. (Some of these parameters are on the Main Solver window in Solver 2010)

Generally you can accept the defaults but in this case we will change the following

Assume Linear Model – Select

Assume Non-Negative – Select

Note: Solver in Excel 2010 will return a better answer without these 2 parameters enabled by default

The other 2 parameters which you may need to change from time to time is

Precision: Precision is a number from 0 to 1 and higher means more precise

Tolerance: Tolerance shows how far away from a Number, an Integer constraint is allowed to be

The use of the Estimates, Derivatives and Search parameters are beyond the scope of this post. I direct you to the Excel Help on these subjects, by selecting the Help button.

Run the Model

To Run the Model, select the Solve Button from the main Solver menu.

The main status bar in Excel will flash up a number of statistics about the internal workings of the Solver add-in. Generally these flash by and are too fast to read. If a model is too complex it may stall and you won’t see any movement for a while. Solver generally recovers from these problems itself.

 

Once the Solver model finishes it will display a dialog of the results and allow you to do several things

First thing to note is that “Solver Found a Solution.

If it has found a solution, the worksheet cells will be changed to show the solution

You now have 4 options:

  • Run a Report
  • Save a Scenario
  • Return to the model
  • Check Your Results

Run a Report

Run a report by clicking the report you want.

A new sheet will be added to your workbook depending on the report but will be called:

  • Answer Report 1,
  • Sensitivity Report 1
  • Limits Reports 1

etc.

Note, that not all reports are relevant at all times, depending on the Constraints you have applied.

Save a Scenario

Selecting the Save a Scenario button takes you to the Save Scenario dialog.

 

Type in a Name and the Scenario of your model is saved as a Scenario.

Scenarios as available for use in the Scenario Manager, which is accessed from the Data, What-If-Analysis Tab

Return to the model

You can return to your model and either:

  • Keep Solver Solution
  • Restore Original Values

Check the Results

Solver is probably the most Black Box’ish of systems within Excel. As such any results it puts out must be manually checked for suitableness before further use.

These checks for realness, should as a start confirm that the results meet all the criteria supplied.

Are the results roughly what were expected?

Are any Minimums or Maximums violated?

 

What If Solver Doesn’t Find a Solution?

From time to time Solver will return with an error that a “Solver could not find a feasible solution.

When this happens it is indicating one of several possibilities:

  • Your model is over or under constrained
  • Your model constraints are impossible to meet
  • Your model constraints have an error

Start by checking the current constraints for errors and ambiguities

Eg: in our case we have 8 items so requiring the Count of the two buckets to be 20 is impossible to meet

 

My Solver Answer has Strange Numbers?

In solver up to and including Excel 2007, solver would commonly return numbers like 3.5E-18.

This is 0.0000000000000000035, which is effectively 0

If your model returns these, feel free to go through the model and change them to 0, in our model we should also check as the corresponding 1, may in fact be 0.9999999999999999965.

It should be noted that this problem in Solver in Excel 2010 does not occur as often but will still occur.

 

What and How have you used solver in the past?

What and How have you used solver in the past?

Let us know in the comments below:

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Overall I learned a lot and I thought you did a great job of explaining how to do things. This will definitely elevate my reporting in the future.
Rebekah S
Reporting Analyst
Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

63 Responses to “To-do List with Priorities using Excel”

  1. Mario 8a says:

    Very useful, you always give us good ideas for our excel files. Thanks
    I've been working on calendars leagues. If you must watch a bit on my blog. http://economiaemergente.com/
     

  2. Jason says:

    EXCELLENTE!!!! 

  3. Rasheed says:

    Needed .. thanks for sharing

  4. [...] To-do List with Priorities using Excel [...]

  5. Gregg says:

    Excellent spreadsheet.  Nice work.

  6. Jose Pedro says:

    Ciao Peppe!, Tante grazie per compartire il tuo eccellentissimo lavoro in Excel. Tu hai a web blog? - Grazie Chandoo per la publicazione.
    Hello Peppe, Thank you so much for sharing your most excellent work in Excel. Have you a web blog? - Thanks Chandoo for publication.

    • PEPPE says:

      Hi Jose,
       tanks for your appreciations and tks to Chandoo for publishing
      my little job.  it's a pleasure for me to be mentioned on my guru's blog. 
      Just to reply to Jose, I don't have a blog, but if you want to share some ideas or need some help don't hesitate to contact me also on twitter like @peppinogreco.
      Regards
      Peppe 

  7. Great!
     
    I've learned a little bit of VBA during the last year, and get addicted to it, but sometimes, it makes us forget how powerful excel is, without macros.
    Nice post!
     
    Cauê

  8. Hi Chandru,
     A very good post. Though I had been reading your posts for a longer time, did not post any questions so far except for wishing and appreciating.
     I have a question here. I had attempted to do something on my own (a little R & D) on the new year resolution template itself. However, I could not do it fully.  Thankfully, you had provided the link for each step , which was exactly what I was looking for 🙂 
     I had done with the check boxes and also conditional formatting. I am glad indeed. I am able to highlight a row when a check box is checked. However, the value of the checkbox gets printed in the same cell which it was linked to. How can I avoid it ? I could not see it in the sample excel files you had provided.
     I appreciate your help in this.
     
    Cheers,
    Raghavan alias Saravanan M
    Jeddah | Kingdom of Saudi Arabia

    • Chandoo says:

      Hi Raghavan... Thanks for your comments and I am glad you are trying to build this on your own. There is no way we can avoid printing the check box value in linked cell. If you do not want to see "TRUE or FALSE" in a cell, you do one of the following.

      • Link check box to a cell in an un-used column. Then hide that column.
      • Link check box to a cell in a different sheet. Then hide that sheet.
      • Link check box to a cell and then hide the cell contents by formatting it with custom code ;;; (more on this here: http://chandoo.org/wp/2009/06/05/hide-cell/ )
  9. Daniel says:

    Dal Messico grazie tanti Peppe.

    A great idea, thanks for shearing it with all of us.
     
    Daniel
     

  10. Lovely idea - downloading now.

    What software is used to create the animated gif of the template in action?  Love to replicate to simple demos on my site.

    Cheers
    Glen 

  11. John says:

    Raghavan

    I just make the font white for the cell linked to the checkbox or if you have shading applied then font colour = shading so its there but is not seen or printed.
    John  

  12. Utku says:

    Excellent! Thank you very much.

  13. Sully says:

    Excellent thanks!

  14. Suresh says:

    Happy New Year.
    Looks simple but excellent. Never knew you could do this without VBA.
    Thanks Pepe

  15. Henrique de Albuquerque says:

    good day,
    Please, how can I create a chart with scroll bar that is also dynamic in PPT.
    I created the chart in Excel, but I need this information to be presented dynamically in powerpoint and when I put the bar rolls loses functionality. please can you help me?

  16. Benny says:

    Come nella migliore tradizione:grandi ma semplici idde dall'Italia.
    bravo Peppe

  17. Vaslo says:

    This was outstanding.  I have had two bosses give me to-do lists that I was very unhappy with.  I went and added 15 more lines to this and it was really easy to so with a little reformatting and changing some links.  THANKS!!!

  18. Aparajita says:

    Thanks. really usuful. Will be waiting for such thing in future.

  19. Juan says:

    Great tutorial! It would be interesting if someone could explain how to do the chart with detail: how to insert the values of the horizontal axis, to create the horizontal bar (the outlines) and the bar itself, etc

  20. DJ says:

    Good Concept!
    Downloaded it but, my Excel 2007 hangs and I have to recover it few times. Finally it opens but, everything is distorted.
    Am I doing something wrong?
     
    -DJ

  21. tadovn says:

    Interesting idea.
    You give e new way to track my actual planning.
    But instead of using thermometer in this case, we can use a simple bar chart , with data is the total done.
    Reasoning for that, with thermometer, you have to format all the small part of data with the same color. If you have more than 10 parts, it will take your time to finish.
    I tested and it shown the same.
     
    I'm searching for How to automatically add check box link to a new cells when we add new item?
    Thanks for your interesting idea.

  22. Munir says:

    Thank you Peppe & Chandoo for sharing an awesome idea.

  23. Sara says:

    How do i increase the list ? I cant just drag down can I ? the check boxes perform the same way

  24. RAVI XAVIER says:

    VERY EXCELLENT THANK YOU VERY MUCH.

  25. Talia says:

    How do you increase the list? Formatting of the check boxes and shading etc does not copy correctly if using copy and paste or dragging cells down...

  26. Pradeep says:

    Thanks for this useful to do list.

    I have the same question as TADOVN. This blog doesn't properly give instruction on how to add new task row. Following are my queries.

    1) How do I add a new row?
    2) If I copy paste the last row to create a new row, the check box get duplicated, i.e. if I click on the new check box on the new row, the previous check box also gets checked.

    So the simple question is.. how do I add a new row so that it behaves the same way as other rows?

  27. Angela G. says:

    Thank you very much! Great to do list template.

  28. Celine says:

    Thanks for the template.

    From an NGO organisation in Malaysia

  29. Leah says:

    Will someone please answer the question about how to add additional rows to this list? I love it, but this is a fatal flaw, as I frequently have many more tasks.

    Thank you!

    • Dennis says:

      Below is how I added additional rows:

      1) Select both columns H and N, right clicked, and clicked Unhide to reveal the formulas.
      2) Select row 12 on the To Do List, copy it, and insert it below in the next row.
      3) Change the 12 in cell C22 to a 13.
      3) Drag your mouse and copy the formulas from cells I15, J15, and K15.
      4) Paste the formulas below in cells I16, J16, and K16.
      5) Right click on the check box in cell F22.
      6) Click Format Control.
      7) Click the Control tab.
      8) In the Cell Link box, change the I15 to I16.
      9) Repeat the steps above. (Change I16 in the Cell Link box to I17...I17 to I18, etc.)
      10) If you are not seeing Format Control when you right click the check box, you need to make the Developer Tab available.

    • Dennis says:

      Leah,

      If you follow my previous instructions, you still may need to go back and change the formulas in column K. They calculate the priority weights and go in consecutive order as you go down the column:

      IFERROR(1/E10,0)
      IFERROR(1/E11,0)
      IFERROR(1/E12,0), etc.

      Some of you who are more Excel savy may be able to figure out how to copy the formulas quicker. This is just the way I figured it out.

  30. Bandula says:

    I am sure I would love this and it will help me to accomplice my tasks efficiently . Thanks Buddy

  31. Sander says:

    How would I be able to delete one of the row (not use 6 for example) so it won't calculate it with the progress?

  32. […] 42,416] Angry Formulas game… [Visitors: 36,392] Learn top 10 Excel features [Visitors: 25,723] To-do list with priorities – Excel templates [Visitors: 19,947] Introduction to Power Pivot [Visitors: 21,298] Best new features in Excel 2013 […]

  33. […] 2013 Calendar, 2012 Calendar, 2011 Calendar, New Year Resolution Tracker, Picture Calendar Template and Todo list template […]

  34. […] ?? ????? ??????????? ?????? ?????? ????? ? ????????????? ??? Excel. ??? ???? ????? ?? ??? […]

  35. Victor says:

    Thank you so much for this post. I took me a bit to figure out how the checkboxes link to the rest of the sheet, but now that I've got it I've created a new page for every day so I can track tasks going forward. I've also added work tasks side-by-side with personal tasks. Once I did that I also thought it would be neat to see how productive I am week over week so I added a nice summery page. The summary builds on the percentage completion for personal and work tasks.

    Love this template - so versatile and yet simple.

    My next project is to get standard weighting for certain tasks so I don't have to keep remembering them.

    Cheers,

    Victor

  36. Jeff Carlsen says:

    I like this template. I may modify how the checkboxes work though for a couple reasons:

    1) It's a pain to add more rows. If I want to add 10 more rows, it appears that I have to re-point each new object to the appropriate link-cell. Otherwise, they all point back to the copied row - checking one causes all of them to check.

    2) I can't group and collapse rows in the checklist without all the objects stacking together and remaining visible in the lowest non-collapsed row. With a simple "x", this would be ok.

    One solution would be to have a simple "x" instead of a checkbox object. I could just use an "x" to mark complete, and make the TRUE/FALSE based on an If formula (If "x" then TRUE; otherwise FALSE).

  37. Kris says:

    I downloaded the file, but it is a ZIP file with several subfolders and xml files. There is no workbook here. How do I open this in Excel?

    thank you for the help and excellent ideas you share.

    • Hui... says:

      @Kris
      Yes, Excel files are special Zip files that actually contain a number of files including your data
      If the file opens like that save it locally as a *.zip file and rename it to a *.xlsx file

      Open with excel normally

  38. s.f says:

    How do you change the color when it is completed....I have multiple companies and need to color code this template.

    Thank you.

  39. Callie says:

    Hello! I have added additional rows, fixed it so that the check boxes work individually, AND made it so that the #% changes when each box is checked -- however the status bar won't move past the midway mark.

    Any ideas on how I can get the progress bar to fill up the entire way once the list is complete?

    • Cheryl says:

      If you right click the status bar, select 'Select Data' and go to 'Chart Data Range' and revise to include your expanded range. The bar chart colors may default to a predefined style. Right click the chart to reformat the Chart Area.

    • Cheryl says:

      Or, to change the bar colors, I populated all rows w/ activities and rank and then left clicked the bar chart color that I wanted to change - went up to the ribbon under the home tab, selected the new bar color from the fill color dropdown.

  40. Cheryl says:

    Love the instant gratification of the status bar! Genius!

  41. Frank says:

    Thank you so much, what a great tool! God bless you for doing this for free!!

  42. rahul saldanha says:

    Awesome
    Nice to show power of excel.

  43. Hui... says:

    Over in the Chandoo.org Forums, Asshu has updated this witha VB Interface

    Have a look and use if from: http://chandoo.org/forum/threads/to-do-list-vb-interface.28973/

  44. Chirag Raval says:

    Dear All,

    There are good job done here & its very helpful for all.
    God Bless You to you all for your valuable working.
    Regards,
    Chirag

  45. Jake says:

    Hi guys,

    I've added additional rows, but the percentages in the thermo-meter don't reflect this when the boxes are checked. I'm lost with how to change this, so any assistance would be greatly appreciated!

    Jake

  46. Peggy Wong says:

    Hi Chandoo, how you do it for all this check list. it is using Excel VBA, I am not good it that.. still leaning part. and I was trying to figure out. Trying to understand all vba code and meaning and when I use which code.

    do you have any guide line on this, i mean. Exp: dim is what, string etc:

    for all this checking list does need to use VBA?

    Thankyou
    Peggy

Leave a Reply