Hello,
For purely academic interests, here is a formula based approach that produces a flat listing.
I have used one helper column, to calculate the cumulative durations.
Source data is assumed to be in A1:C5 as shown in the sample:
[pre]
Code:
# A B C
1 Product Duration CumDuration
2 ProductA 10 10
3 ProductB 20 30
4 CIP 3 33
5 ProductC 4 37
i.e. first product is listed in cell A2, etc.
For ease of reference, I have also used the following Named Ranges:
PList refers to A2:A5
PDuration refers to B2:B5
CumDuration refers to C2:C5
CumDuration was calculated as =SUM(B$2:B2) in cell C2, and then copied down through C5.
In my sample output, I have put them in the range E8:G14, and looks as follows:
# E F G
8 Day Product Duration
9 1 ProductA 10
10 1 ProductB 14
11 2 ProductB 6
12 2 CIP 3
13 2 ProductC 4
14 … … …
[/pre]
In cell E8, put the following formula (entered with Ctrl+Shift+Enter):
=IF(SUM(G$8:G8)>=SUMPRODUCT(PDuration), "…", IF(N(E8)=0, 1, IF(SUMIFS(G$8:G8, E$8:E8, E8)>=24, E8+1, E8)))
Copy it to the rows below (i.e. through E14)
In cell F8, put the following formula (entered with Ctrl+Shift+Enter):
=IF(SUM(G$8:G8)>=SUMPRODUCT(PDuration), "…",INDEX(PList, MATCH(1, IF(CumDuration-SUM(G$8:G8) > 0, 1), 0)))
Copy it to the rows below (i.e. through F14)
In cell G8, put the following formula (entered with Ctrl+Shift+Enter):
=IF(SUM(G$8:G8)>=SUMPRODUCT(PDuration), "…",IF(INDEX(PDuration, MATCH(1, IF(CumDuration-SUM(G$8:G8) > 0, 1), 0)) - SUMIFS(G$8:G8, F$8:F8,F9) > 24-SUMPRODUCT(--(E$8:E8=E9), IF(ISNUMBER(G$8:G8), G$8:G8, 0)), 24-SUMPRODUCT(--(E$8:E8=E9), IF(ISNUMBER(G$8:G8), G$8:G8, 0)), INDEX(PDuration, MATCH(1, IF(CumDuration-SUM(G$8:G8) > 0, 1), 0)) - SUMIFS(G$8:G8, F$8:F8,F9)))
Copy it to the rows below (i.e. through G14)
As the last row in the sample output shows, if you copy the formula to more rows than available duration to allocate, it will display "..."
I have not attempted to optimize the formulas in any way, since this was more to illustrate what is possible with just formulas. If anyone wants to know what the formulas are doing, let me know, and I can write up an explanation.
Cheers,
Sajan.