How many Kits Available


November 17, 2017 - by

How many Kits Available

Today, an interesting Excel problem about bills of material. You have a lot of raw materials. Each item might be assembled into several different top-level assemblies. Based on the raw material on hand, do you have enough to fulfill an order for a certain item?


Watch Video

  • Tim asks: How many of each item is available to sell
  • Complicating factor: An item is comprised of multiple cartons
  • Bill Method #1: Add a helper column with INT(Qty Needed/On Hand)
  • Add Subtotals for the Min of Helper at each change in Product
  • Collapse Subtotals to the #2 View
  • Select all data. Use Alt + ; for Select Visible Cells
  • Paste to a new range
  • Ctrl + H to change Space Min to nothing
  • Mike Method #2
  • Copy the Product column to the right and use Data, Remove Duplicates
  • Next to the unique list of products, use MINIFS
  • Note that MINIFS is only available in Office 365
  • Bill Method #3: a regular pivot table fails because Calculated Fields won't work in this case.
  • Select one cell in your data and press Ctrl + T to convert to a table.
  • Instead, as you are creating the pivot table, choose the box for Add to Data Model
  • Create a new measure for Available to Sell using INT
  • Create a new measure for Kit Available to Sell using MINX
  • That pivot table works!
  • Mike Method #4 Use AGGREGATE function.
  • It seems like you would want to use MIN argument, but use SMALL because it handles arrays
  • Use =AGGREGATE(15,6,INT($D$2:$D$141/$C$2:$C$141)/($A$2:$A$141=F2),1)
  • AGGREGATE is one of five functions that can accept an array as an argument without Ctrl + Shift + Enter
  • Bill Method #5
  • Convert the data to a table and use Power Query - aka Get & Transform
  • In Power Query, calculate OH/Needed
  • Use the Number.RoundDown function to convert to integer
  • Use Grouping by Part Number and Min Avail
  • Close & Load
  • Bonus: It is refreshable!

Video Transcript

MrExcel:              Hey, welcome back, it's time for another Dueling Excel Podcast. I'm Bill Jelen from MrExcel, I'll be joined by Mike Girvin from Excel Is Fun. This is our Episode 190: How Many Kits are Available to Sell?

Alright, today's question sent in by Tim. Watches our Dueling Excel videos, he works for a retailer and asked to create a spreadsheet to show our sales team what we own and what we can sell. Sounds simple, right? But here's the catch: The item they sell contains multiple cartons and are inventoried on a per carton basis. Here's an example of what he's seeing. So here's this item, P12345, has 3 different things that they have to ship. And in the kit, requires 4 of Carton 1, 1 of Carton 2, and 1 of Carton 3. And this is how many they have in stock. Alright, so just doing the math here, they have 2 complete sets of Carton 1, 4 complete sets of Carton 2, and 3 complete sets of Carton 3. But that means what they can sell is the minimum of those 3 numbers-- they can only sell 2. And here, they have 4 complete sets of Carton 4, 4 of Carton 5, 2 of Carton 3, only 1 of Carton 7-- that's the limiting item. So, in this case, they can only sell one of these. Alright. Now, a question for a later day, I said, "Well, is there any chance that Carton 3 is used in more than one place?" And he says, "Yes, but we're going to worry about that later." Alright.

So here's how I'm going to attack this. I can actually think of several different ways to attack this, so this might be interesting-- this might be a back and forth type of duel. What I'm going to do is, I want to have a Helper column out here, And the Helper column is going to look on an item-by-item basis of how many we can sell. So = 8 divided 4, like that, and we'll double click to copy it down. But, let's say that we needed 4, and we had 6. Alright, so now it's going to say 1.5. Well you can't sell, you know, half a couch, alright? So, it's going to have to be the whole number. So what I'm going to do here, is use the =INT-- INT, the integer-- that thing which will take off the decimals and leave us just the whole amount. Alright. So then we have 8-- back to the original number.

And we need to figure out, for each item here, what's the smallest number over in Column E? Make sure the data's sorted by Product, go to the Data tab, choose Subtotals, at each change in Product, use the Min function. You know, I teach Subtotals all the time at my Power Excel seminars, and I point out there's 11 functions here but I've never used anything other than Sum and Count. So while Subtotal may not be the fastest way to do this, I want to be able to say that there was actually one time where I was able to use something other than Sum and Count. Alright, click OK. And what we're going to get, is every time the curtain number-- the product number-- changes, we get to see the Min. And that Min is the answer that we want. So I collapsed down to the number 2 view, I'll select all of this data, and Alt+; to select just the visible cells, Ctrl+C, and then we'll come down here and paste-- let's just paste out to this area-- Ctrl+V. Alright. Delete the extra columns and then we have to get rid of the word Min. And not just the word Min, but space Min. Alright. So I'm going to use Ctrl+H and change the recurrence of space Min to nothing, Replace All, click OK, click Close, and there's our table of what we have available to sell. Alright, Mike, I'll throw it over to you.

Mike:                     Wow! MrExcel, I love it. The Min function in Subtotals. How cool is that? Alright, I'm going to go over to this sheet right here, I'm going to do the same Helper column. =INT we'll take all "On Hand" divided by "Required Quantity", close parentheses. Ctrl+Enter, double-click, and send it down. Now, I just need to find the Min available for a given condition or criteria. I'm going to select Product, Ctrl+Shift+Down Arroe, Ctrl+C to copy, then I'm going to Right Arrow, Ctrl+V, then I'm going to come up and say Remove Duplicates. There it is.

I used to use Advanced Filter, Unique Records Only all the time, but it seems like this method is faster. There's my unique list. Now I'm going to come over here. How many? And I'm going to use the new function, MINIFS. Now, MINIFS is in Office 365; for Excel 2016 or later, the MINRANGE. Well, I need to find the minimum value in this column, Ctrl+Shift+Down Arrow, F4, comma and the criteria range-- that's going to be this whole product. Ctrl+Shift+Down Arrow, F4, comma, Left Arrow, and there we go. That will get the min value from how many, based on the condition or criteria, close parentheses, Ctrl+Enter, double-click and send it down. Alright. So there's MINIFS and Subtotal. I'm going to throw it back over to you MrExcel.

MrExcel:               Yes, Mike, very nice. Remove Duplicates, get the unique list of products, and then the MINIFS function. I asked him what version of Excel he's on, he said Excel 2016. I hope it's Office 365 version of 2016, so he has access to that. Well, how about a Pivot Table? Alright, so I created a Pivot Table with Product, and Requires, Sum of Required Quantities, and Sum of On Hand. Then from right here, "Analyze", "Fields, Items & Sets", "Calculated Field", and created a new calculated field called "Available", which is On Hand divided by Required Quantity-- that way I don't need the Helper Column over here. And at first it seemed like it was going to work because we had 2, 3, and 4 and the reporting that the minimum is 2-- I changed this calculation, of course, to Min, and that seemed good.

But then, on this one, where we have 2,4,4,1,2, it's reporting 3. And what's happening is it's doing the calculation on this row. We have 25 on hand, divided by 8, that's 3 and a fraction, and so it's reporting 3, and so, no. A regular Pivot Table calculate item is not going to work. But instead, convert this data to a table and then Insert, PivotTable, Add this data to the Data Model, click OK. And we're going to have, down the left-hand side, Product and what it Requires. I'm going to create two implicit measures here with a Required Quantity and some of On Hand, and then I'm going to create a new measure. So, PowerPivot, Measure, a New Measure, and this new measure will be called Available to Sell (AvailToSell) and that formula is going to be, how many we have on hand divided by how many are required for each item, and click OK. Alright, so 8 divided by 4 is 2.

Alright. Now, that's still not our right answer, and we probably need to run this through the Integer function. So, Measures, Manage Measures, edit this and wrap the whole thing inside the INT function like this, click OK, and click Close. Now we're getting a fractional number-- still the wrong answer here.

But we're going to use a great new function that's only available in DAX. New Measure, and this is going to be called KitAvailable, and the function is not MIN, but MINX-- MINX. The MINX function. And the table that we're going to use is Table 1, and then expression is going to be that Available to Sell that we just calculated, and what this does-- the MINX function evaluates on a row by row basis and finds the minimum error. And so, we'll click KitAvailable, OK. Well, check this out: So here, where we have 2, 4, 4, 1, and 2, it's reporting 1. Alright, now in a perfect world all we have is Product and KitAvailable-- we don't need any of this other stuff in the middle. Alright. So we're just going to check this here, 2, 1, 3, 2, are our answers. I'll take the Requires out, 2, 1, 3, 2, yes. It's going to work. We actually take all the intermediate calculations out, just have a KitAvailable, like that. Mike, do you have another one?

Mike:                     How cool is that, MrExcel? You use the MINX function in DAX; well, I'm going to go back over here, I'm going to use a formula. But I'm going to pretend like I don't even have this Helper column. I used MINIFS. Well, before MINIFS, in Excel 2016 there was the AGGREGATE function in Excel 2010. Now I want to use MIN, but of course, functions 1 to 13 do not let you do array formulas. So I'm going to have to use SMALL 1 as a substitute for the MIN function. And SMALL is one of the functions, 14 and above, that can handle array operations. That argument right there, array. So function number 15, comma, I want to ignore divided by zero error, so I'm going to type a 6 to ignore errors, comma, and I need to simulate that whole Helper column in the array argument-- INT. And instead of simply saying On Hand divided by Require, we do the whole column, Ctrl+Shift+Down Arrow, F4, divided by the Required column-- Ctrl+Shift+Down Arrow, F4-- now close parenthesis. That INT right there, if I highlight this and hit F9, it simulates that entire How Many Helper column. Ctrl+Z, now I simply divide it by, in parentheses, I need to get an array of TRUES and FALSEs, so I click on Product, Ctrl+Shift+Down Arrow, F4, and I ask the question are any of you equal to that Product ID, close parentheses. That will give me a bunch of TRUES and FALSEs. F9 TRUES and FALSEs in the denominator, TRUE will become a 1, FALSE will become a 0, which will give us divide by zero error. Ctrl+Z.

In essence, if I click the whole array in here, F9, the divide by zero is going to be our filter, so we only see the numbers for a particular Product. Ctrl+Z, and then, of course, AGGREGATE will pick the min out from that array of errors and numbers, close parenthesis. And AGGREGATE's amazing-- one of five functions that has an argument that can handle array operations without Ctrl+Shift+Enter. So I simply Ctrl+Enter and F2. What did I forget? Backspace. Array, then I type a comma and the K is 1 because I always want SMALL 1, which is the min, close parentheses. Ctrl+Enter, double-click, and send it down, F2. Alright. Aggregate with that whole Helper column right there to get how many for each Product. Alright? I'm going to throw it back over to MrExcel.

MrExcel:               Hey, that's beautiful. I knew there'd be a lot of different ways to solve this. I did not think of using AGGREGATE, which of course is better, because if someone has 2010, this will work. The 15 allows an array out here that is gorgeous. Alright, now, hey, when I set up the question, I just missed this and, you know, and Mike, you know this, when people send us questions, they try and minimize the situation to make it sound like it's easy, but the thing that's going to be a disaster here, is the fact that Carton 3 is used in multiple places, alright? And as soon as they sell something from, let's say, they sell, like, this item P12346, well then the number of Carton 3s on hand is going to change, right? And so that's going to impossibly impact what else we can sell.

Alright. So, thinking about how Tim is going to have to manage this process, he's going to have to have a way to regenerate this item quickly. And so, hopefully, he has an inventory table for every item. It'll show how many there are on hand and then, a VLOOKUP here, to pull the inventory over. Alright? That's what I'm hoping is going to happen, because then it might become somewhat manageable. And if this is something we have to reproduce again and again and again, then Power Query definitely has a use here.

So, Power Query in Excel 2010 or 2013, you're going to go download it, you'll have your own Power Query tab; but in Excel 2016, you're going to look for the Get and Transform. It's funny, in Excel 2016, it was the second group, but then in Office 365 they moved it to be the first group. Power Query has the ability to take something from a Table or Range, so I'm going to choose one cell in this table, Ctrl+T-- that will create a table for me. Table 3 is a fine name, I don't need to rename that. Now, this is the Table, we go to Data, From Table or Range, and we are going to Add a new Column-- this column is going to be a Custom Column, it's going to be called "Available", and that is going to be the On Hand divided by Required Quantity. Alright. Now, we need to send this into the INT function. Unfortunately, the function and Power Query are not the same. So, click here and then go to Formula Types, and you'll find this function is called Number.RoundDown, and this is case sensitive-- you have to make sure to use that exact same case. So =Number.RoundDown, open paren, and closed paren, and click OK. And so 11 divided by 4 is 2.75, rounds down to 2. Alright. That's the answer we need there, we don't need these columns anymore. So I can click on Requires, Shift+click on On Hand, and remove those columns. Alright. Now, choose Product, Transform, Group By, we're going to group by the Product, and the new function is going to be called KitsAvailable, and the operation is going to be the min of the available column. Click OK. Alright.

So now we have Product and KitsAvailable. Home, Close & Load, get a brand new sheet with our answers, but here's the beautiful thing. Alright, so, when we sell something-- let's make these columns less wide-- and we sell, let's say we sell enough so we have no Carton 3s left, I change that number there, the VLOOKUPS bring the results, and then come back here and choose this and Refresh all. And you see that now we have none of this, and this, and this, available to sell, because they all needed that Carton 3, and we have none of those left. Being able to Refresh in Power Query is going to help this in the end.

Well, this was a fun one for me because I knew there would be a lot of different ways to solve this problem. The Episode wrap up of this really long Episode: How many of each item is available to sell? And there's multiple cartons, alright? So, the first thing I did was add a Helper column; and then use Subtotals with the Min function; and then a whole bunch of really boring steps. Make had method number two, used MINIFS, which is great if you have Office 365. I went back to a Pivot Table, but a regular Pivot Table won't work, instead had to do a Data Model and then use the MINX function-- the MINX function-- and that calculated field or measure will actually work. Mike, using the AGGREGATE function, beautiful function, one of five functions that can accept an array as an argument without Ctrl+Shift+Enter. And then, method 5, convert the data to a table and use Power Query, also known as Get & Transform; and we're going to calculate On Hand divided by Needed (Required); and then the Number.RoundDown function to convert to an integer; group by part name, number, and calculate the minimum available; Close & Load; and the bonus, it's refreshable.

Well, hey, I want to thank you for stopping by, we'll see you next time for another Dueling Excel Podcast from MrExcel and Excel is Fun.

Download File

Download the sample file here: Duel190.xlsx

Title Photo: minarikovamichaela87 / Pixabay