Oggi, un interessante problema di Excel sulle distinte base. Hai molte materie prime. Ogni articolo può essere assemblato in diversi assiemi di primo livello differenti. In base alla materia prima disponibile, hai abbastanza per evadere un ordine per un determinato articolo?
Guarda un video
- Tim chiede: quanti di ogni articolo sono disponibili per la vendita
- Fattore di complicanza: un articolo è composto da più cartoni
- Metodo di fatturazione n. 1: aggiungi una colonna helper con INT (quantità necessaria / disponibile)
- Aggiungi i totali parziali per il Min di Helper a ogni modifica del prodotto
- Comprimi i totali parziali nella vista n. 2
- Seleziona tutti i dati. Usa alt = "" +; per Seleziona celle visibili
- Incolla in un nuovo intervallo
- Ctrl + H per cambiare Space Min in niente
- Mike Metodo # 2
- Copia la colonna Prodotto a destra e usa Dati, Rimuovi duplicati
- Accanto all'elenco univoco di prodotti, utilizza MINIFS
- Tieni presente che MINIFS è disponibile solo in Office 365
- Metodo di fatturazione n. 3: una normale tabella pivot non riesce perché i campi calcolati non funzioneranno in questo caso.
- Seleziona una cella nei tuoi dati e premi Ctrl + T per convertirli in una tabella.
- Invece, mentre crei la tabella pivot, scegli la casella Aggiungi al modello di dati
- Creare una nuova misura per Disponibile per la vendita utilizzando INT
- Crea una nuova misura per Kit disponibile per la vendita utilizzando MINX
- Quella tabella pivot funziona!
- Mike Method # 4 Usa la funzione AGGREGATE.
- Sembra che tu voglia usare l'argomento MIN, ma usa SMALL perché gestisce gli array
- Uso
=AGGREGATE(15,6,INT($D$2:$D$141/$C$2:$C$141)/($A$2:$A$141=F2),1)
- AGGREGATE è una delle cinque funzioni che possono accettare un array come argomento senza Ctrl + Maiusc + Invio
- Metodo di fatturazione n. 5
- Converti i dati in una tabella e usa Power Query, ovvero Recupera e trasforma
- In Power Query, calcolare OH / Needed
- Utilizzare la funzione Number.RoundDown per convertire in numero intero
- Utilizzare il raggruppamento per numero di parte e disponibilità minima
- Chiudi e carica
- Bonus: è aggiornabile!
Trascrizione del video
MrExcel: Ehi, bentornato, è tempo per un altro Podcast di Dueling Excel. Sono Bill Jelen di, sarò raggiunto da Mike Girvin di Excel Is Fun. Questo è il nostro episodio 190: quanti kit sono disponibili per la vendita?
Perfetto, la domanda di oggi inviata da Tim. Guarda i nostri video di Dueling Excel, lavora per un rivenditore e ha chiesto di creare un foglio di calcolo per mostrare al nostro team di vendita cosa possediamo e cosa possiamo vendere. Sembra semplice, vero? Ma ecco il trucco: l'articolo che vendono contiene più cartoni e viene inventariato in base al cartone. Ecco un esempio di ciò che sta vedendo. Quindi ecco questo articolo, P12345, ha 3 diverse cose che devono spedire. E nel kit, richiede 4 del cartone 1, 1 del cartone 2 e 1 del cartone 3. E questo è quanti ne hanno in magazzino. Va bene, quindi solo facendo i conti qui, hanno 2 set completi di Cartone 1, 4 set completi di Cartone 2 e 3 set completi di Cartone 3. Ma ciò significa che ciò che possono vendere è il minimo di quei 3 numeri - loro può venderne solo 2. E qui hanno 4 set completi di Cartone 4,4 di Cartone 5, 2 di Cartone 3, solo 1 di Cartone 7: questo è l'articolo con limite. Quindi, in questo caso, possono vendere solo uno di questi. Tutto a posto. Ora, una domanda per un giorno successivo, ho detto: "Bene, c'è qualche possibilità che Carton 3 venga utilizzato in più di un posto?" E lui dice: "Sì, ma di questo ci preoccuperemo più tardi". Tutto a posto.
Quindi ecco come lo attaccherò. Posso effettivamente pensare a diversi modi per attaccarlo, quindi potrebbe essere interessante - questo potrebbe essere un tipo di duello avanti e indietro. Quello che farò è, voglio avere una colonna Helper qui, e la colonna Helper cercherà articolo per articolo di quanti possiamo venderne. Quindi = 8 diviso 4, in questo modo, e faremo doppio clic per copiarlo. Ma diciamo che ne avevamo bisogno 4 e ne avevamo 6. Va bene, quindi ora diremo 1.5. Beh, non puoi vendere, sai, mezzo divano, va bene? Quindi, dovrà essere il numero intero. Quindi quello che farò qui, è usare = INT-- INT, il numero intero-- quella cosa che toglierà i decimali e ci lascerà solo l'intero importo. Tutto a posto. Quindi abbiamo 8 … torna al numero originale.
E dobbiamo capire, per ogni elemento qui, qual è il numero più piccolo nella colonna E? Assicurati che i dati siano ordinati per Prodotto, vai alla scheda Dati, scegli Subtotali, ad ogni modifica in Prodotto, usa la funzione Min. Sai, insegno sempre ai totali parziali durante i miei seminari su Power Excel e faccio notare che ci sono 11 funzioni qui, ma non ho mai usato nient'altro che Somma e Conteggio. Quindi, anche se Subtotal potrebbe non essere il modo più veloce per farlo, voglio essere in grado di dire che c'è stato effettivamente un momento in cui sono stato in grado di usare qualcosa di diverso da Sum and Count. Va bene, fai clic su OK. E ciò che otterremo, è che ogni volta che il numero del sipario, il numero del prodotto, cambia, possiamo vedere il Min. E quel Min è la risposta che vogliamo. Quindi sono crollato nella vista numero 2, selezionerò tutti questi dati e Alt +;per selezionare solo le celle visibili, Ctrl + C, quindi scendiamo qui e incolliamo - incolliamo in quest'area - Ctrl + V. Tutto a posto. Elimina le colonne extra e poi dobbiamo eliminare la parola Min. E non solo la parola Min, ma lo spazio Min. Tutto a posto. Quindi userò Ctrl + H e cambierò la ricorrenza dello spazio Min in niente, Sostituisci tutto, fai clic su OK, fai clic su Chiudi, e c'è la nostra tabella di ciò che abbiamo a disposizione per la vendita. Va bene, Mike, te lo do.e c'è la nostra tabella di ciò che abbiamo a disposizione per vendere. Va bene, Mike, te lo do.e c'è la nostra tabella di ciò che abbiamo a disposizione per vendere. Va bene, Mike, te lo do.
Mike: Wow! MrExcel, lo adoro. La funzione Min in subtotali. Quant'è fico? Va bene, vado a questo foglio proprio qui, farò la stessa colonna Helper. = INT prenderemo tutto "On Hand" diviso per "Quantità richiesta", chiudi parentesi. Ctrl + Invio, fai doppio clic e invialo. Ora, ho solo bisogno di trovare il Min disponibile per una determinata condizione o criterio. Selezionerò Prodotto, Ctrl + Maiusc + Freccia giù, Ctrl + C per copiare, quindi vado a Freccia destra, Ctrl + V, quindi vengo su e dirò Rimuovi duplicati. Eccolo.
Usavo sempre Filtro avanzato, Solo record unici, ma sembra che questo metodo sia più veloce. C'è la mia lista unica. Adesso vengo qui. Quanti? E userò la nuova funzione, MINIFS. Ora, MINIFS è in Office 365; per Excel 2016 o versioni successive, MINRANGE. Bene, devo trovare il valore minimo in questa colonna, Ctrl + Maiusc + Freccia giù, F4, virgola e l'intervallo di criteri: sarà l'intero prodotto. Ctrl + Maiusc + Freccia giù, F4, virgola, Freccia sinistra e via. Questo otterrà il valore minimo da quanti, in base alla condizione o ai criteri, chiudi parentesi, Ctrl + Invio, fai doppio clic e invialo. Tutto a posto. Quindi ci sono MINIFS e Subtotal. Lo restituirò a te.
MrExcel: Sì, Mike, molto gentile. Rimuovi i duplicati, ottieni l'elenco univoco dei prodotti e quindi la funzione MINIFS. Gli ho chiesto quale versione di Excel si trova, ha detto Excel 2016. Spero sia la versione di Office 365 del 2016, quindi ha accesso a quella. Bene, che ne dici di una tabella pivot? Va bene, quindi ho creato una tabella pivot con prodotto e richiede, somma delle quantità richieste e somma delle disponibilità. Quindi da qui, "Analizza", "Campi, articoli e set", "Campo calcolato" e ha creato un nuovo campo calcolato chiamato "Disponibile", che è Disponibile diviso per Quantità richiesta - in questo modo non ho bisogno la Colonna dell'Assistente qui. E all'inizio sembrava che avrebbe funzionato perché avevamo 2, 3 e 4 e la segnalazione che il minimo è 2-- Ho cambiato questo calcolo, ovviamente, in Min,e questo sembrava buono.
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,? 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: 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.
Bene, ehi, voglio ringraziarti per essere passato, ci vediamo la prossima volta per un altro Podcast Dueling Excel da MrExcel ed Excel è divertente.
Download file
Scarica il file di esempio qui: Duel190.xlsx