It got me thinking of another sceanrio where this would be helpful.
If I have 10 tests in my semester and my grades are like this: [....]
What do I need to average on the remaining tests inorder to
attain an 85% average. I tried to adapt the formulas posted
but could not get it to work correctly.
In general, if D1 is the number of events (20 for sales days; 10 for
scores), D2 is the goal (100 for sales; 85% for scores, which can also be
written 0.85), and D3 is the round-up precision that you want (0 for sales;
2 for percentage -- explained below), the overall formula can be written:
=IF(COUNT(B2:INDEX(B2:B1000,D1))=D1,0,
ROUNDUP(MAX(0,D2-SUM(B2:INDEX(B2:B1000,D1)))/(D1-COUNT(B2:INDEX(B2:B1000,D1))),D3))
The expression INDEX(B2:B1000,D1) returns reference to B2 plus D1-1; so
B2:INDEX(...) is the range from B2 to B2 plus D1-1.
We might find the alternative expressions OFFSET(B2,0,0,D1) and
INDIRECT("B2:B" & 2+D1-1) more readable. But those are "volatile"
expressions; they cause that cell and any dependent cells to be recalculated
whenever any cell in any worksheet in the workbook is modified (and some
other times). That might not be so bad if you have a simple workbook.
Otherwise, it can be the cause of significant delays.
The round-up precision for percentage is 2, not 0, because 85% is actually
the number 0.85, for example.
If you find the ROUNDUP usage confusing, you can eliminate it. Simply
write:
=IF(COUNT(B2:INDEX(B2:B1000,D1))=D1,0,
MAX(0,D2-SUM(B2:INDEX(B2:B1000,D1)))/(D1-COUNT(B2:INDEX(B2:B1000,D1))))
But beware that you might come up short of your goal due to rounding.