Interactive summation - excel

I'm trying to get this programmed in Excel:
The variables you can change are Points and Steps. In the table there comes the value for each step until all the points/steps are given. The values beneath that has to be zero. I used the function Numbervalue to check some assumptions, but that didn't workout:
=IF(NUMBERVALUE(Previous_Cell) < POINTS;Previous_Cell+ POINTS_PER_CELL;0)
After the 2 points, the next cell becomes zero. But then the whole list starts over. So there has to be some function that says: If Previous_CELL = 0 then THIS_CELL = 0.

Assuming Points is in A1, in B6:
=IF(OR(SUM(B$5:B5)>B$2,B5=B$2),"",B$3*(MOD(ROW()-1,B$2)+1))
and in C6, with both copied down to suit:
=IF(OR(SUM(C$5:C5)>C$2,C5=C$2),"",C$3*(MOD(ROW()-6,C$2)+1))

Related

Excel Find the first zero after a non zero within a range

I have a range, that contains data which follows a distribution *typically starts at 0, then goes up, then down, and finally back to zero.
I want to return the value of another column at the point that the data returns back to Zero (in my case you can see that Cell B6 is the point at which this event occurs, and I want my cell C2 to return the value "E" from cell A6...
Currently, the best I can get to is the following:
=INDEX(A2:B8,FIND(0,
TEXTJOIN(,,B2:B8),
MATCH(AGGREGATE(4,4,B2:B8),B2:B8,0)) -1,1)
The problem comes in with the fact that there can be any number of zeros before the data appears.
i.e. like this. = Where I would still expect the highlighted match.
1] 1st zero after a non-zero value, in C2 enter formula :
=INDEX(A:A,INDEX(MATCH(1,1/B:B),0)+1)
2] Nos. of zero after a non-zero value, in D2 enter formula :
=MATCH(9^9,B:B)-INDEX(MATCH(1,1/B:B),0)
For excel you can use INDEX/AGGREGATE:
=INDEX(A:A,AGGREGATE(15,6,ROW(B2:B8)/(B2:B8=0),2))
Edit:
If you want get first zero value after last non zero value use formula:
=INDEX(A:A,AGGREGATE(14,6,ROW(B2:B8)/(B2:B8<>0),1)+1)

Calculate current streak in Excel row

I have a list of 1s and 0s in excel row ranging from B2:K2, I want to calculate the current streak of 1's in cell M2,
example dataset where streak would be 4
1 0 1 0 1 1 1 1 0
Is there a simple way of doing this? I have tried research but not been able to find anything specific.
Any help would be much appreciated.
Here is a way of doing this with just one formula, no helper columns/rows needed:
The formula used translates to:
{=MAX(FREQUENCY(IF(B1:K1=1,COLUMN(B1:K1)),IF(B1:K1=1,0,COLUMN(B1:K1))))}
Note: It's an array formula and should be entered through CtrlShiftEnter
Assuming your data is layed out horizontally like the image below, the following two formulas should do it for you.
The first cell requires a different formula as the is no cell to the left to refer to. so a simple formula to check if the first cell is one or not is entered in B2.
=--(A1=1)
The part in the bracket will either be true or false. A quirk of excel is that if you send a true or false value through a math operation it will be converted to 1 for true and 0 for false. That is why you see the double - in front. could have also done *1, /1, +0,-0 at the end.
In B2 place the following formula and copy right as needed:
=(A2+1)*(B1=1)
Basically it adds 1 to the series, then check if the number in the sequence is 1 or 0. In the event its one, it keeps the value as it is TRUE sent through the math operator *. If it is false it set the sequence back to zero by multiplying False by the math operator *.
Alternate IF
Now the above while it works and may save a few characters is not necessarily intuitive for most. The go to option would be to use an IF function. The above formulas can be replaced with the following:
A3
=IF(A1=1,1,0)
B3 ->Copied right
=IF(B1=1,A3+1,0)
Longest streak
To get the longest streak, the highest value in your helper row is what you want. You can grab this with the following formula in an empty cell.
=MAX(2:2)
=MAX(A2,I2)
If you have no other numbers in your helper row, you can use the first formula which looks in the entire row. If there are other numbers due to calculations off to the left or right as an example, then you will want to restrict your range to you data as in the second formula.
I've put those values in cells B2 to B8.
In cell C3, I've put this formula:
=IF(AND(B3=1;B2=1);C2+1;1)
Dragging this downto C8, and then take the maximum of the C column.

Let Excel Solver Operate with Natural Numbers

My workbook is a bit complicated, but the basic problem can be illustrated with a short example.
Let's assume that I have 5 cells in Excel: A, B, C, D, and E.
A = 0
B = 5 * A
C = 0
D = 10 * C
E = B + D
In the Excel Solver Function I select cell E as the objective that is to be maximised, and cells A and C as the variable cells. Furthermore, I add the constraint that cell E must not exceed 10, and the second constraint that cells A and C must be integers.
The ideal solution would be that the value in cell A should be 0, and the value in cell C should be 10. In the more complicated version of this problem, however, Excel cannot find the optional solution.
The way the current formulas look like I expect that Excel could find the right solution, if excel only used natural numbers to find the optimal solution. For example, Excel currently would look at the outcome for A = 0.01 and C = 9.99. Instead, Excel should strictly compare outcomes for variable choices such as A = 1 and C = 9.
How can I make the Excel solver function operate with natural numbers only?
I suggest you keep your current cells, and create a mirror set beside them. Each mirror cell will equal the rounded version of the original cell. ie: RoundedA will have the formula:
=ROUND(A,0)
Then when you do your data analysis, solve for the rounded version of those cells, with the changing variable being one of the "original" cells.
EDIT
As discussed below, you may need to 'trick' data validation into creating the values you want.
Assume A1 is going to be your "testing" data validation cell. B1 is a permanently blank cell. Set another cell, say, C1, equal to:
=randbetween(1,10)
This will create a random integer between 1 and 10. Set your "variable" cell to be equal to C10. So, your variable cell will always be a random number between 1 & 10 (or you could set "1" equal to the smallest number of your other variables, and "10" equal to the largest number of your other variables. This will create the scope needed to answer your question).
Then when you do data validation, make it try to get A1 = TRUE. Do this by figuring out what the 'test' condition is of your cells. Something like "when X = 0, I know that all my variables are correct". ie set A1 to:
=if(X=0,1,0)
Then do data validation by changing B1 (your blank, unrefered-to cell), waiting until A1 = 1. Does that make sense? It will turn C1 into the random cycling variable between LOWVALUE and HIGHVALUE, always using integers. Data validation will stop when A1 = 1 (which happens when some value X = 0). B1 will just spin uselessly until Data validation finds something (or it will stop after a few hundred tries if it finds nothing).
To get Solver to try larger increment divide the target cells by a large number and in such a way, each increment that solver tries is larger. (for example it changes the target cells by +-0.00001 - in that case divide the target cells by 100000 or more).

If cell 1 contains w cell 2 should equal x, if cell 1 contains y cell 2 should contain z

I'm trying to make an automated character sheet for D&D and for the equipment I would like to set it up so if the list of equipment the character has contains any individual weapon, the stats for making attack with that weapon appear in the attacks section. I've been using a formula referencing a table of all the statistics of all weapons on another part of the same sheet, and I can make it work for no more than two weapons. This is the formula:
=IF(OR(M13=A115);B115;IF(M13=A116;B116))
M13 is the the list of equipment the character has
A115=Club
B115=1d4 BL
A116=Greatclub
b116=1d8 BL
Note that the first part of the IF function is an OR function and the second part is another IF function. I don't know if that means you can only have one IF and one OR function in the overall IF function, but it will not work if I try changing the second IF function to an OR function, giving me error 504 and if I try changing the OR function to an IF function I get #VALUE!
To put it in simpler terms if cell C1=A1 D1 should equal B1. If C1=A2 D1 should equal B2 and so on.
I see where your going with that IF formula (I think), but what I think you really want is a =VLOOKUP:
=VLOOKUP(M13, A115:B200, 2, false)
This will search the range A115:A200 for the value in M13. When it finds it, it will stick the value from the corresponding B row into the cell where this formula exists.

Store an integer in a cell and use that to set the number of column gaps

I'm creating a revenue model on a simple spreadsheet. On the top, I have a variable cell (C5) that is the "number of weeks between transactions". Below that, I have a simple weekly revenue model.
Problem: What I would like is to be able to tweak the fields in yellow and have it apply dynamically to the model below so that it applies the sales amount from C4 every X weeks to the model below, where X is C5.
My initial guess was to use OFFSET, such as F10 =SUM(OFFSET(C10,0,$C$5)), but I've never used this function before and the more I think about it, I'm not sure if I'm approaching this correctly at all.
I created a mock desired results image to show what I would like to have happen if I enter 3 in C5 and then change it to 2.
May not be quite right but hopefully 'configurable' to suit. Assumes $500 is entered in C10 and (at least for the time being) 1 will not be entered in C5. Please try in D10 and copied across to suit:
=IF(MOD(COLUMN()-3,$C5)<MOD(COLUMN()-4,$C5),$C10,"")
A quick fix for the above failing to populate all cells when C5 is 1 is to wrap the formula in the condition =IF($C5=1,$C10,....)
MOD "returns the remainder after a number is divided by a divisor". The remainder being 0 when the number is an exact multiple of the divisor. If we take the first example (every third column) a suitable divisor is 3. Put =MOD(Column(),3) in A1 and copy across and the result is 1, 2, 0, 1, 2, 0, 1, ..... (Column() returns a number representing the column letter, with 1 for A, 2 for B etc., or the actual Column Heading where R1C1 reference style is checked under Working with formulas, in Formulas within Excel Options.)
So that establishes a series where every third position is identifiable as returning a value from MOD that is less than that of the immediately preceding cell. For the second example (every second column) with a divisor of 2 =MOD(Column(),2) in A1 copied across results in 1, 0, 1, 0, 1, ... so again the reduction in the remainder signals the position required for the formula to output the requisite value.
We are comparing the result of calculating the remainder for one column relative to the result of the same calculation performed on the previous column, hence -3, -4. Other (suitably paired) values might work equally well, it just seemed easier to 'start from zero' when in the first column for the formula (ColumnD or 4).
(If anybody would like to provide a proper explanation please feel free to edit!)

Resources