Skip the navigation

How to solve optimization problems with Excel and Solver

Whether it's minimizing costs or maximizing returns, this excerpt from the book Data Smart shows you how to use Excel's Solver add-in

By John W. Foreman
February 18, 2014 06:18 AM ET

An optimization problem is one where you have to make the best decision (choose the best investments, minimize your company's costs, find the class schedule with the fewest morning classes, or so on). In optimization models then, the words "minimize" and "maximize" come up a lot when articulating an objective.

In data science, many of the practices, whether that's artificial intelligence, data mining, or forecasting, are actually just some data prep plus a model-fitting step that's actually an optimization model. We'll start with a little practice with optimization now. Just a taste.

In Excel, optimization problems are solved using an Add-In that ships with Excel called Solver.

On Windows, Solver may be added in by going to File (in Excel 2007 it's the top left Windows button) > Options > Add-ins, and under the Manage drop-down choosing Excel Add-ins and pressing the Go button. Check the Solver Add-In box and press OK.

On Mac, Solver is added by going to Tools then Add-ins and selecting Solver.xlam from the menu.

A Solver button will appear in the Analysis section of the Data tab in every version.

All right! Now that Solver is installed, here's an optimization problem: You are told you need 2,400 calories a day. What's the fewest number of items you can buy from the snack stand to achieve that? Obviously, you could buy 10 ice cream sandwiches at 240 calories a piece, but is there a way to do it for fewer items than that?

Solver can tell you!

To start, download a copy of the Calories spreadsheet from the book's companion website at www.wiley.com/go/datasmart -- use the download link for chapter 1. Make a copy of the Calories sheet in the Concessions.xlsx Excel workbook, name the sheet Calories-Solver, and clear out everything but the calories table on the copy. If you don't know how to make a copy of a sheet in Excel, you simply right-click the tab you'd like to copy and select the Move or Copy menu.

To get Solver to work, you need to provide it with a range of cells it can set with decisions. In this case, Solver needs to decide how many of each item to buy. So in Column C next to the calorie counts, label the column How many? (or whatever you feel like), and you can allow Solver to store its decisions in this column.

Our Commenting Policies