SOLVED

Seedling distribution

%3CLINGO-SUB%20id%3D%22lingo-sub-2890744%22%20slang%3D%22en-US%22%3ESeedling%20distribution%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2890744%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20looking%20for%20some%20Excel%20help%20to%20help%20us%20organize%20a%20tree%20planting%20plan%20for%20a%20project%20we%20are%20doing.%20We%20have%20base%20data%20that%20includes%20farmers'%20names%2C%20the%20species%20of%20seedlings%20they%20want%20to%20plant%20and%20the%20qty%20of%20each%20species.%20We%20need%20to%20sort%20this%20data%20into%20bags%20of%20seedlings.%20Each%20bag%20can%20have%20a%20maximum%20of%2025%20seedlings%20and%20we%20try%20to%20keep%20the%20species%20together%2C%20but%20sometimes%20two%20or%20more%20species%20can%20share%20the%20same%20bag.%20I%20have%20worked%20out%20some%20formulas%20to%20assign%20bag%20numbers%20but%20I%20am%20stumbling%20over%20the%20task%20of%20allocating%20the%20species%20to%20the%20bags.I%20have%20attached%20a%20sample%20of%20what%20the%20data%20looks%20like%20and%20how%20we%20are%20trying%20to%20organize%20it.%3C%2FP%3E%3CP%3EIf%20there%20is%20a%20clever%20formula%20or%20function%20or%20some%20VBA%20that%20someone%20could%20help%20me%20with%2C%20I%20will%20be%20very%20grateful.%20I%20can%20usually%20manage%20fine%20with%20formulas%20but%20my%20VBA%20skills%20are%20copy%20and%20paste.%20We%20tried%20sorting%20this%20data%20manually%20but%20there%20are%20around%201.3%20million%20seedlings%20and%208000%20farmers%20and%20planting%20season%20begins%20next%20week.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2890744%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2890896%22%20slang%3D%22en-US%22%3ERe%3A%20Seedling%20distribution%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2890896%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F730392%22%20target%3D%22_blank%22%3E%40ms_mit%3C%2FA%3E%26nbsp%3BI%20am%20not%20sure%20if%20I%20had%20solved%20your%20problem.%20Please%20check%20sheet%202.%20I%20have%20used%20Pivot.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2891327%22%20slang%3D%22en-US%22%3ERe%3A%20Seedling%20distribution%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2891327%22%20slang%3D%22en-US%22%3E%3CP%3Elet%20me%20reach%20home%20and%20look%20at%20your%20post%20again%20so%20I%20can%20help..I%20am%20on%20the%20road%20taxi%20reading%20this%20Hope%20you%20have%20the%20excel%20file%20attached%20so%20I%20can%20take%20a%20logical%20look%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2891578%22%20slang%3D%22en-US%22%3ERe%3A%20Seedling%20distribution%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2891578%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F730392%22%20target%3D%22_blank%22%3E%40ms_mit%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDo%20you%20want%20to%20calculate%20the%20number%20of%20bags%20and%20the%20number%20of%20remaining%20seedlings%3F%20I%20applied%20the%20following%20formulas%20to%20do%20this%3A%3C%2FP%3E%3CP%3E%3DSUMIFS(%24D%246%3A%24D%2434%2C%24C%246%3A%24C%2434%2CJ4%2C%24A%246%3A%24A%2434%2CI4)%3C%2FP%3E%3CP%3E%3DROUNDDOWN(K4%2F%24B%243%2C0)%3C%2FP%3E%3CP%3E%3DMOD(K4%2C%24B%243)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECould%20you%20communicate%20the%20formulas%20to%20assign%20bag%20numbers%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2895653%22%20slang%3D%22en-US%22%3ERe%3A%20Seedling%20distribution%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2895653%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F730392%22%20target%3D%22_blank%22%3E%40ms_mit%3C%2FA%3E%26nbsp%3BI%20have%20created%20a%20vba%20for%20sheet2.%20I%20could%20not%20fill%20BagNo.%20Please%20check%20once.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2895806%22%20slang%3D%22en-US%22%3ERe%3A%20Seedling%20distribution%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2895806%22%20slang%3D%22en-US%22%3EHi%20Jitinm%2C%20Thanks%20for%20that.%20It%20calculates%20the%20full%20bags%20(of%2025)%20and%20the%20remainder%20correctly.%20Do%20you%20have%20any%20idea%20how%20to%20enumerate%20a%20list%20with%20the%20individual%20line%20items%3F%20So%20for%20example%20Farmer1%20%2B%20Mahogany%20%3D%203%20bags%20of%2035%20seedlings%20each%20becomes%3A%3CBR%20%2F%3EFarmer1%20%7C%20Mahogany%20%7C%2025%3CBR%20%2F%3EFarmer1%20%7C%20Mahogany%20%7C%2025%3CBR%20%2F%3EFarmer1%20%7C%20Mahogany%20%7C%2025%3CBR%20%2F%3E.....%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2895904%22%20slang%3D%22en-US%22%3ERe%3A%20Seedling%20distribution%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2895904%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F730392%22%20target%3D%22_blank%22%3E%40ms_mit%3C%2FA%3E%26nbsp%3BSince%20you%20mention%20to%20have%201.3%20million%20seedling%20to%20distribute%20to%208000%20farmers%2C%20you%20should%20look%20into%20Power%20Query.%20Played%20around%20a%20bit%20with%20your%20example%20and%20came%20up%20with%20a%20%22solution%22%20that%20needs%20refinement.%20Half%20of%20it%20is%20in%20PQ.%20For%20the%20other%20half%20I%20cheated%20a%20bit%20by%20adding%20some%20manual%20columns%20in%20Excel.%20Should%20be%20possible%20to%20do%20those%20in%20PQ%20as%20well%20but%20have%20the%20inspiration%20right%20now.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2896078%22%20slang%3D%22en-US%22%3ERe%3A%20Seedling%20distribution%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2896078%22%20slang%3D%22en-US%22%3EHey%20Riny%2C%20That%20is%20exactly%20what%20I%20need.%20Thank%20you!!!%20Helper%20columns%20work%20fine%20for%20me.%20This%20is%20a%20thing%20I%20need%20immediately%20so%2C%20if%20it%20works%2C%20it's%20good.%20I%20can%20figure%20out%20the%20bits%20with%20the%20helper%20columns.%20Can%20you%20please%20point%20me%20toward%20where%20to%20open%20your%20bits%20of%20PQ%3F%20I%20need%20to%20study%20how%20this%20works.%3CBR%20%2F%3EThanks%20again!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2896209%22%20slang%3D%22en-US%22%3ERe%3A%20Seedling%20distribution%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2896209%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%20I%20had%20a%20look%20at%20your%20PQ%20setup%20and%20I%20have%20to%20admit%20that%20for%20now%20it%20is%20over%20my%20head%20but%20I%20will%20come%20back%20to%20it%20and%20learn%20it.%20In%20the%20mean%20time%2C%20I%20wonder%20If%20I%20could%20ask%20you%20if%20you%20have%20any%20ideas%20for%20an%20alternate%20solution.%20I%20am%20using%20this%20data%20as%20the%20basis%20for%20printing%20labels%20for%20all%20the%20bags%20of%20seedlings%20and%20it%20would%20be%20more%20workable%20to%20put%20the%20species%20in%20the%20shared%20bags%20in%20a%20single%20row%2C%20rather%20than%20more%20rows%20of%20the%20same%20bag%20number.%26nbsp%3B%20I%20have%20attached%20a%20file%20with%20the%20structure%20I%20am%20talking%20about.%20If%20it%20you%20have%20a%20quick%20idea%20how%20to%20do%20this%2C%20I%20would%20very%20much%20appreciate%20it.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2899081%22%20slang%3D%22en-US%22%3ERe%3A%20Seedling%20distribution%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2899081%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20Riny%2C%20This%20gets%20me%20on%20the%20road%20to%20the%20solution.%20I%20have%20used%20PQ%20in%20the%20past%20for%20some%20simple%20aggregation%20of%20data%20from%20multiple%20worksheets%20but%20nothing%20like%20the%20transforms%20you%20are%20doing%20here.%20Admittedly%2C%20I%20don't%20understand%20the%20queries%20you%20created%2C%20especially%20the%20steps%20in%20the%20Append1%20and%20what%20the%20GRT%20function%20does%20but%20I%20will%20eventually%20figure%20it%20out.%3C%2FP%3E%3CP%3EI%20did%20run%20this%20query%20with%20a%20full%20dataset.%20Takes%20about%2015%20minutes%20to%20run%20even%20with%20a%20relatively%20powerful%20computer.%20But%20it%20works.%20Now%20I%20just%20have%20to%20figure%20out%20how%20to%20transpose%20the%20species%20and%20seedling%20count%20for%20the%20mixed%20bags.%3C%2FP%3E%3CP%3EThanks%20also%20for%20the%20link%20to%20the%20PQ%20tutorial.%20It%20looks%20like%20a%20good%20one.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2899214%22%20slang%3D%22en-US%22%3ERe%3A%20Seedling%20distribution%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2899214%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F730392%22%20target%3D%22_blank%22%3E%40ms_mit%3C%2FA%3E%26nbsp%3BGreat%20you%20could%20get%20it%20to%20work.%20And%20what's%2015%20minutes%20for%20a%20job%20that%20would%20otherwise%20take%20perhaps%20a%20whole%20day%20of%20copying%20and%20pasting.%20Now%20that%20I%20look%20back%20at%20the%20query%2C%20I%20see%20I%20was%20over-thinking%20the%20matter%20by%20adding%20the%20Grouped%20Running%20Total.%20We%20can%20do%20without%20and%20it%20will%20probably%20speed%20up%20the%20process.%20See%20attached.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

I am looking for some Excel help to help us organize a tree planting plan for a project we are doing. We have base data that includes farmers' names, the species of seedlings they want to plant and the qty of each species. We need to sort this data into bags of seedlings. Each bag can have a maximum of 25 seedlings and we try to keep the species together, but sometimes two or more species can share the same bag. I have worked out some formulas to assign bag numbers but I am stumbling over the task of allocating the species to the bags.I have attached a sample of what the data looks like and how we are trying to organize it.

If there is a clever formula or function or some VBA that someone could help me with, I will be very grateful. I can usually manage fine with formulas but my VBA skills are copy and paste. We tried sorting this data manually but there are around 1.3 million seedlings and 8000 farmers and planting season begins next week.

20 Replies

@ms_mit I am not sure if I had solved your problem. Please check sheet 2. I have used Pivot.

Hi Jitin, Thanks for the help. Pivot tables are a wonderful thing but I also tried using them and couldn't get it. The problem I am working on is finding a formula (or set, or some code), to parcel these gross amounts (i.e. 80 mahogany for a particular farmer) into individual bags of 25 seedlings, or some limit like that. So in other words, I'd end up with 3 bags of 25 mahogany each, with a remainder of 5 which would go in the next bag of 5 mahogany and 20 teak. Does that make sense?

let me reach home and look at your post again so I can help..I am on the road taxi reading this Hope you have the excel file attached so I can take a logical look

@ms_mit 

Do you want to calculate the number of bags and the number of remaining seedlings? I applied the following formulas to do this:

=SUMIFS($D$6:$D$34,$C$6:$C$34,J4,$A$6:$A$34,I4)

=ROUNDDOWN(K4/$B$3,0)

=MOD(K4,$B$3)

 

Could you communicate the formulas to assign bag numbers?

Hey @Quadruple_Pawn, thanks for helping

My formula for assigning bag numbers is

=COUNTIF($A$6:A6,A6)&"/"&ROUNDUP(SUMIF($I$3:$K$14,A6,$K$3:$K$14)/$B$3,0.1)

But it is just counting instances of the Farmer name. This only works until I have a bag with more than one species in it, then it breaks.

 

Your formulas are, I think, approaching it the other way around. The data I showed is example only. What I am trying to calculate is the lists in columns A:D. I only have the data in the base data columns I:K. Nearly 20,000 rows of it that I have to parcel out into a list like A:D.

I am sure there is a way, it's just really testing my excel skills.

@ms_mit I have created a vba for sheet2. I could not fill BagNo. Please check once.

Hi@DonaldTrumpFan I have put a fresh copy of my Excel file here if you want to give it a try. As I mentioned below, My goal is to assemble the list of bags of tree seedlings on the left side of this worksheet from the data included in the 'Base Data' table to the right.I am still stumped about how to enumerate a list of Farmer Names according to the qty of seedlings each one gets and then further assign tree species in the correct number to that list and finally the qty of seedlings of each species that goes in eat bag. It becomes more complicated when there are multiple species in one bag. Any help you can give will be very much appreciated.

Ultimately, I have to run the final list through a mail merge to do a whole lot of labels but that is another subject.

Hi Jitinm, Thanks for that. It calculates the full bags (of 25) and the remainder correctly. Do you have any idea how to enumerate a list with the individual line items? So for example Farmer1 + Mahogany = 3 bags of 35 seedlings each becomes:
Farmer1 | Mahogany | 25
Farmer1 | Mahogany | 25
Farmer1 | Mahogany | 25
.....?
Can you share working in excel for example how it should look. That would help much.

@ms_mit Since you mention to have 1.3 million seedling to distribute to 8000 farmers, you should look into Power Query. Played around a bit with your example and came up with a "solution" that needs refinement. Half of it is in PQ. For the other half I cheated a bit by adding some manual columns in Excel. Should be possible to do those in PQ as well but have the inspiration right now.

Hi@jitinm I have cleaned up the formating a bit to hopefully make it easier to understand. Here is the idea basically. I have the 'Base Data' you see in the table on the right. I have to transform this data to a list like what you see in the 'Results Data' on the left. The transform goes roughly like this: The first line of the Base data is:

Farmer NameTree SpeciesQty of Seedlings
Farmer 1Mahogany75

 

I need to find formulas or VBA to transform this into a list like this:

Farmer NameSpeciesSeedling qty per bagBag No.
Farmer 1Mahogany251/10
Farmer 1Mahogany252/10
Farmer 1Mahogany253/10

 

But then it gets more complicated. Some species are not divisible by 25 (max seedlings per bag) so there is a remainder. This means we have to group one of more species of seedlings into a single bag, so it means one bag has more than one row of data (but it still has the same bag number). Does that make sense? Let me know if you have another idea. The data could also be arranged with the multi species bags in more than one column. At the end, this results data will be used to print labels for all the bags so workers can go and fill the bags with the correct seedlings

Hey Riny, That is exactly what I need. Thank you!!! Helper columns work fine for me. This is a thing I need immediately so, if it works, it's good. I can figure out the bits with the helper columns. Can you please point me toward where to open your bits of PQ? I need to study how this works.
Thanks again!
Understood, there must be some additional column in your base data which specifies which one has single bag or multiple bag. I mean the vba I shared added multiple columns and I used some logic to distribute the qty as per 25 rule( I hope my vba solved your first/earlier query?). So to create additional logics there must be some input in your base data to do.

Hi@Riny_van_Eekelen I had a look at your PQ setup and I have to admit that for now it is over my head but I will come back to it and learn it. In the mean time, I wonder If I could ask you if you have any ideas for an alternate solution. I am using this data as the basis for printing labels for all the bags of seedlings and it would be more workable to put the species in the shared bags in a single row, rather than more rows of the same bag number.  I have attached a file with the structure I am talking about. If it you have a quick idea how to do this, I would very much appreciate it.

@ms_mit Well, if you are completely unfamiliar with PQ, this is not very straight-forward. The file I uploaded has quite some "non-stadard" coding, and is not really a finished product. Not sure if you are going to master it if you are in a hurry. What you could try is take the attached file and dump your real data in the structured table called "Table1" with exactly the same column names. Then press Refresh on the Data ribbon and see what happens.

 

More about the PQ basic here:

https://exceloffthegrid.com/power-query-introduction/ 

 

 

 

@Riny_van_Eekelen 

Thanks Riny, This gets me on the road to the solution. I have used PQ in the past for some simple aggregation of data from multiple worksheets but nothing like the transforms you are doing here. Admittedly, I don't understand the queries you created, especially the steps in the Append1 and what the GRT function does but I will eventually figure it out.

I did run this query with a full dataset. Takes about 15 minutes to run even with a relatively powerful computer. But it works. Now I just have to figure out how to transpose the species and seedling count for the mixed bags.

Thanks also for the link to the PQ tutorial. It looks like a good one.

best response confirmed by allyreckerman (Microsoft)
Solution

@ms_mit Great you could get it to work. And what's 15 minutes for a job that would otherwise take perhaps a whole day of copying and pasting. Now that I look back at the query, I see I was over-thinking the matter by adding the Grouped Running Total. We can do without and it will probably speed up the process. See attached.

 

 

 

 

@Riny_van_EekelenYes it works great.For some reason it is filling a lot of seemingly redundant rows with empty Qtys but this is easily filtered out.

For sure it would have been more than just one day of cutting and pasting to assemble this list. The finished list has around 70,000 rows. It has also showed me that we have considerable non-unique Farmer Names. But this is also easily fixed.

Thanks again for your help with this Riny.

@Quadruple_PawnFor some strange reason, I received your latest solution by email notification but it is not shown in the comments of this thread. And no sample file is here to download. Anyway I did paste in your "Seedling" code and the formula for doing the bag numbers. I found that it works for all the seedling quantities that are 25 or more. Any quantities below 25, it ignores....which also throws off the bag number formula. If you have a solution for that, I would really appreciate it.

 

Another strange thing is that When I run this on an almost full data set (31,000 rows) the code throws an overflow error on the line "z = z + 1". Alternately, I I run the full data set (33,764 rows), after changing the line "For i = 4 To 33764", it immediately gives an overflow error. I guess I could break the data set up and run separate smaller sets but it would be interesting to know why this happens.

 

I have attached a file with some actual data in it, so you can see what happens with the problem of ignoring the <25 quantities.