Lookup tied to a maximum sum value

SLARRA

Board Regular
Joined
Sep 22, 2007
Messages
93
I have a table of expected outputs by calendar day. I want to specify a target number of outputs (user entry, cell B1), then for any given start date, calculate the end date whose elapsed period (given that start date) will yield at least that target amount of outputs.

Example follows - I need a formula (prefer not to use VBA) that will calculate the stop dates, shown in red in Column E (note: for the sake of this example, I manually determined the appropropriate stop dates an inseted them in Column E).
Excel Workbook
ABCDEF
1Target output:4Units
2
3
4Expected Output( Units by Date)Date Rangeto AchieveTarget Output
5
6DateUnitsStartDateStopDateUnits Yield
71/1/201201/1/20121/7/20124
81/2/201201/2/20121/7/20124
91/3/201201/3/20121/7/20124
101/4/201211/4/20121/7/20124
111/5/201201/5/20121/8/20125
121/6/201211/6/20121/8/20125
131/7/201221/7/20121/8/20124
141/8/201221/8/20121/12/20124
151/9/20120etc
161/10/20121
171/11/20120
181/12/20121
191/13/20121
20etc
Sheet1
Excel 2007
Cell Formulas
RangeFormula
F7=SUMIFS($B$7:$B$19,$A$7:$A$19,">="&D7,$A$7:$A$19,"<="&E7)
F8=SUMIFS($B$7:$B$19,$A$7:$A$19,">="&D8,$A$7:$A$19,"<="&E8)
F9=SUMIFS($B$7:$B$19,$A$7:$A$19,">="&D9,$A$7:$A$19,"<="&E9)
F10=SUMIFS($B$7:$B$19,$A$7:$A$19,">="&D10,$A$7:$A$19,"<="&E10)
F11=SUMIFS($B$7:$B$19,$A$7:$A$19,">="&D11,$A$7:$A$19,"<="&E11)
F12=SUMIFS($B$7:$B$19,$A$7:$A$19,">="&D12,$A$7:$A$19,"<="&E12)
F13=SUMIFS($B$7:$B$19,$A$7:$A$19,">="&D13,$A$7:$A$19,"<="&E13)
F14=SUMIFS($B$7:$B$19,$A$7:$A$19,">="&D14,$A$7:$A$19,"<="&E14)


Thanks in advance!

SDL
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
can you write out the logic for this? for example its target output divided by units of output?

I don't understand how you arrive at the dates column e. If you do that ill give it a go.

*I think col A and B show how many units can be produced each day, but in not sure how it needs to be worked out.
 
Upvote 0
Thanks for the help!

The problem is pretty simple, but I suspect the solution (formula) may be difficult.

Simply put, I'm trying to determine, for any given start date, what stop date will ensure (at least) the target amount of output units have been produced.

I want to produce at least 4 units (the target amount, as shown in the yellow cell in my example posting). And, I have that table that shows the expected output by calendar day. So, if - for example - I started on 1/1, we can see where I would attain that target amount of outputs by 1/7, with 1 unit produced on 1/4, 1 more unit on 1/6, and the final 2 units on 1/7. To get the stop date, I sum down the expected outputs column, starting with the row associated with 1/1. Once that running sum reaches 4 (or first exceeds 4), I now know the first stop date that ensures the production of 4 (or more) units of output.

If I started production on 1/5, I'd have to work until 1/8 to achieve the target amount of outputs. In that case, I'd actually produce 5 units (that is, 1/8 is the first end date that satisfies or exceeds the target production of 4 units, in this case exceeding it by 1 extra unit - but that's OK).

Since what I really want is the associated stop dates (I entered those stop dates in red manually, but want a formula to figure them out for me), this is some sort of a constrained sum and associated lookup. But, I have no idea how to replicate my manual process with a formula.

Thanks for helping me!

SDL
 
Upvote 0
I have a table of expected outputs by calendar day. I want to specify a target number of outputs (user entry, cell B1), then for any given start date, calculate the end date whose elapsed period (given that start date) will yield at least that target amount of outputs.

Example follows - I need a formula (prefer not to use VBA) that will calculate the stop dates, shown in red in Column E (note: for the sake of this example, I manually determined the appropropriate stop dates an inseted them in Column E).

Excel Workbook
ABCDEF
1Target output:4Units
2
3
4Expected Output( Units by Date)Date Rangeto AchieveTarget Output
5
6DateUnitsStartDateStopDateUnits Yield
71/1/201201/1/20121/7/20124
81/2/201201/2/20121/7/20124
91/3/201201/3/20121/7/20124
101/4/201211/4/20121/7/20124
111/5/201201/5/20121/8/20125
121/6/201211/6/20121/8/20125
131/7/201221/7/20121/8/20124
141/8/201221/8/20121/12/20124
151/9/20120etc
161/10/20121
171/11/20120
181/12/20121
191/13/20121
20etc
Sheet1
Excel 2007
Cell Formulas
RangeFormula
F7=SUMIFS($B$7:$B$19,$A$7:$A$19,">="&D7,$A$7:$A$19,"<="&E7)
F8=SUMIFS($B$7:$B$19,$A$7:$A$19,">="&D8,$A$7:$A$19,"<="&E8)
F9=SUMIFS($B$7:$B$19,$A$7:$A$19,">="&D9,$A$7:$A$19,"<="&E9)
F10=SUMIFS($B$7:$B$19,$A$7:$A$19,">="&D10,$A$7:$A$19,"<="&E10)
F11=SUMIFS($B$7:$B$19,$A$7:$A$19,">="&D11,$A$7:$A$19,"<="&E11)
F12=SUMIFS($B$7:$B$19,$A$7:$A$19,">="&D12,$A$7:$A$19,"<="&E12)
F13=SUMIFS($B$7:$B$19,$A$7:$A$19,">="&D13,$A$7:$A$19,"<="&E13)
F14=SUMIFS($B$7:$B$19,$A$7:$A$19,">="&D14,$A$7:$A$19,"<="&E14)



Thanks in advance!

SDL
Try this...

Note that this will only work in Excel versions 2007 and later (too many nested functions for earlier versions).

Enter this array formula** in E7:

=INDEX(A$19:INDEX(A$7:A$19,MATCH(D7,A$7:A$19,0)),MATCH(TRUE,SUBTOTAL(9,OFFSET(B$7,MATCH(D7,A$7:A$19,0)-1,,ROW(INDIRECT("1:"&COUNT(A$19:INDEX(A$7:A$19,MATCH(D7,A$7:A$19,0)))))))>=B$1,0))

** array formulas need to be entered using the key combination of CTRL,SHIFT,ENTER (not just ENTER). Hold down both the CTRL key and the SHIFT key then hit ENTER.

Format as Date

Copy down as needed.
 
Upvote 0
I can't do that without VBA.... Perhaps someelse could provide a user defined function for it so at least it only a code once.


Code:
Option Explicit
Sub SumTo()
    Dim lngLastRow As Long
    Dim lngLoopCtr As Long
    Dim lngSumTotal As Long
    lngSumTotal = 0
    lngLastRow = Range("A" & Rows.Count).End(xlUp).Row
    For lngLoopCtr = 6 To lngLastRow Step 1
        lngSumTotal = lngSumTotal + Cells(lngLoopCtr, "B")
        If lngSumTotal >= Range("e1") Then
            MsgBox "The total is = " & lngSumTotal & " for cell 'A" & lngLoopCtr & "'."
            Exit For
        End If
    Next lngLoopCtr
End Sub


This seems to do the the evaluation at least... but perhaps some else can help with the rest (Im stuck)




**** See now someelse has it MUCH simplier than me :-) *** are well I tried
 
Last edited:
Upvote 0
Big thanks to both Shadow (for taking a whack at this, tho I haven't tried your VBA method yet and certainly can't finish the code since I'm VBA illiterate) and T.Valko/Biff for the formula solution that works!

I'm trying to digest what Biff's formula is doing - lotta stuff going on there! - but the main point is that it works!

Funny, I would have guessed that this kind of running-sum lookup would be a relatively common problem posed to Excel, yet we can see from the complexity of your solutions that it's a bit of a tough nut to crack.

Thanks, again, for the help - it is much appreciated.
 
Upvote 0
Big thanks to both Shadow (for taking a whack at this, tho I haven't tried your VBA method yet and certainly can't finish the code since I'm VBA illiterate) and T.Valko/Biff for the formula solution that works!

I'm trying to digest what Biff's formula is doing - lotta stuff going on there! - but the main point is that it works!

Funny, I would have guessed that this kind of running-sum lookup would be a relatively common problem posed to Excel, yet we can see from the complexity of your solutions that it's a bit of a tough nut to crack.

Thanks, again, for the help - it is much appreciated.
You're welcome. Thanks for the feedback! :cool:
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,749
Members
452,940
Latest member
rootytrip

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