Slotting Calculation Challenge

dcbuzzell

New Member
Joined
Jan 22, 2013
Messages
36
Struggling to find the way to do this. Have a table of rows (product) called Table1, including a date column for ReadyToStart which indicates when it will be ready, and a date column WeekMonday which is the Monday of the week for ReadyToStart

ItemReadyToStartWeekMonday
1amb15/28/245/27/24
1amn15/29/245/27/24
1amt16/5/246/3/24


Another table called tblSlotting with a date column WeekMonday which gives the Monday of each week and a number column Slots for the number of items that can be produced that week.
WeekMondaySlots
5/27/241
6/3/240
6/10/242

The number of product ReadyToStart in a given work week will usually exceed the Slots for its ReadyToStart week. Need to be able determine a StartDate in the ReadyToStart week until it equals the Slots; then for the next row move it to the following week with sufficient Slots, and continue this through all rows for Table1

The result should be:

ItemStartDate
1amb15/28/24
1amn16/3/24
1amt16/10/24

Any suggestions?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Power Query:
let
    // list of slots
    tblSlotting = Excel.CurrentWorkbook(){[Name="tblSlotting"]}[Content],
    s = Table.TransformColumns(
        Table.SelectRows(tblSlotting, (x) => x[Slots] > 0), 
        {"Slots", (x) => List.Repeat({null}, x)}
    ),
    slots = List.Buffer(Table.ExpandListColumn(s, "Slots")[WeekMonday]),
    // products
    Table1 = Table.Sort(Excel.CurrentWorkbook(){[Name="Table1"]}[Content], "ReadyToStart"),
    prod = List.Buffer(Table1[WeekMonday]),
    // use slots
    find_slot = (k, skp) => 
        [
            i = k,
            pos = List.PositionOf(List.Skip(slots, skp), prod{i}, Occurrence.First, (c, v) => c >= v),
            slot_position = pos + skp,
            skip = slot_position + 1
        ],
    gen = List.Generate(
        () => find_slot(0, 0),
        (x) => x[i] < List.Count(prod) and x[pos] <> -1,
        (x) => find_slot(x[i] + 1, x[skip]),
        (x) => slots{x[slot_position]} 
    ),
    result = Table.FromList(
        List.Zip(Table.ToColumns(Table1) & {gen}),
        (x) => {x{0}, if x{3} is null then "no slot found" else if x{2} = x{3} then x{1} else x{3}},
        {"Item", "StartDate"}
    )
in
    result
 
Upvote 0
Solution

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top