I encountered "64 levels of nesting" issue while working on my formula. Is there any way to simplify this formula? This formula worked fine up from 10 to 500 (G:G) but once over 510 something, it encountered "64 levels of nesting" issue. I found some solutions that involved lookup and match-index, but I can't see where/how to implement it here.
Formula is in cell B3:
=IF(B2<=$G$2,B2+($E$2*B2),IF(AND(B2>$G$2,B2<=$G$3),B2+($E$3*B2),IF(AND(B2>$G$3,B2<=$G$4),B2+($E$4*B2),IF(AND(B2>$G$4,B2<=$G$5),B2+($E$5*B2),IF(AND(B2>$G$5,B2<=$G$6),B2+($E$6*B2),IF(AND(B2>$G$6,B2<=$G$7),B2+($E$7*B2),IF(AND(B2>$G$7,B2<=$G$8),B2+($E$8*B2),IF(AND(B2>$G$8,B2<=$G$9),B2+($E$9*B2),IF(AND(B2>$G$9,B2<=$G$10),B2+($E$10*B2),IF(AND(B2>$G$10,B2<=$G$11),B2+($E$11*B2),IF(AND(B2>$G$11,B2<=$G$12),B2+($E$12*B2),IF(AND(B2>$G$12,B2<=$G$13),B2+($E$13*B2),IF(AND(B2>$G$13,B2<=$G$14),B2+($E$14*B2),IF(AND(B2>$G$14,B2<=$G$15),B2+($E$15*B2),IF(AND(B2>$G$15,B2<=$G$16),B2+($E$16*B2),IF(AND(B2>$G$16,B2<=$G$17),B2+($E$17*B2),IF(AND(B2>$G$17,B2<=$G$18),B2+($E$18*B2),IF(AND(B2>$G$18,B2<=$G$19),B2+($E$19*B2),IF(AND(B2>$G$19,B2<=$G$20),B2+($E$20*B2),IF(AND(B2>$G$20,B2<=$G$21),B2+($E$21*B2),IF(AND(B2>$G$21,B2<=$G$22),B2+($E$22*B2),IF(AND(B2>$G$22,B2<=$G$23),B2+($E$23*B2),IF(AND(B2>$G$23,B2<=$G$24),B2+($E$24*B2),IF(AND(B2>$G$24,B2<=$G$25),B2+($E$25*B2),IF(AND(B2>$G$25,B2<=$G$26),B2+($E$26*B2))))))))))))))))))))))))))
Cells $A2:$A26 & cells $E2:$E26 are variable. Cells $D2:$D26 are just my indicator. Others are constant value.
Cells $B2:$B26 will calculate the formula $A2+$A2* percentage. The percentage is based on the value which is in cells $E2:$E26. The value is then determine by the value in cells $A2:$A26.
Formula in cells $B2:$B26 are as previous formula dragged down.
Example:
If the cost is 50. The value of percentage will be taken from cell $E$7. In this case is 10 thus returning the value in $B$6 to $A6+$A6*10=55
Please refer to ss 2.
excel screenshot 2
If you reach the nesting limit that nearly always means there's an easier way....
You should be able to do this much more simply with a lookup type formula, e.g.
=B2+B2*IF(B2<G$2,E$2,INDEX(E$3:E$26,MATCH(TRUE,INDEX(B2>G$2:G$25,0),0))
This finds the first value in column G which is > B2 and then gets the required value from the next row in column E
The only thing this formula doesn't do is impose an upper limit on B2 (yours is the G26 value 250). If that's an issue you can just add an extra IF to cater for that
You might want to rework your tables but an INDEX/MATCH with a relative lookup on ascending data will return the correct percentage.
=b2*index(e2:e26, match(b2, g2:g26, 1))
Not 100% sure I understand your formula/intent. I think I got it...if not please clarify.
add another column that does the math in column H. enter this formula and drag down.
=($B$2+(E2*$B$2))
in cell B3 enter this formula
=VLOOKUP(ROUNDUP(B2,-1),G:H,2,FALSE)
Related
I'm trying to find a formula to calculate the balance of a column until a negative value is found. After the negative value is found, the balance must be calculated again until the next negative value. Basically tracking what you spent, except it only shows a value when you sold something. Anybody have an idea if this is possible to do in MS excel? Thanks!
OK. Now I get your question. I think the following will do the trick. The results exactly match your example.
// In these cells only
F2: =MAX(0,B2*C2)
G2: =MAX(0,B2)+MIN(0,B2)
// In these cells, then copy down
E3: =IF(B3<0,D3-(F2-F3),"")
F3: =F2+MAX(0,B3*C3)+IF(G2=0,0,MIN(0,B3*F2/G2))
G3: =G2+MAX(0,B3)+MIN(0,B3)
I would note a couple of things about this:
1) You might consider changing the names of your columns to trans, quan, $ per, $ ttl, $ gp, and name the 2 columns I am adding $ inv and inv.
2) This is using the average cost of inventory, recalculated with each transaction, not LIFO or FIFO.
3) If entries get out of order such that quan goes negative, I think this solution will fail. In any case, that might be an error you'd want to notice.
4) FYI, the "IF(G2=0" part of F3 is only there to avoid a divide by 0 error when G2 (inventory) is 0. I could have done this other ways, of course. It works.
5) I've left E2 blank on the assumption that you can't sell as you've not bought.
One way would be to add 2 additional columns, which could be hidden or on another sheet, then (here assuming adding columns F2 and G2 added at the right):
In Cell E2: =IF(B2<0,G2,"")
In Cell F2: =B2*C2
In Cell G2: =SUM(F$2:F2)
Copy these down and, assuming I understand your question correctly, you'll get the results you desire.
The biggest problem you've got with this is working out the ranges to check for the balance calculation. This won't work if the next row in your table is a 'sell' while you've still got one 'apple' left from the previous purchase. If you want to do anything more convoluted you should use VBA.
Others will probably have an easier way to work out the ranges; I did it in a rather convoluted way and don't have time to optimise them.
In column F there's an array formula to calculate the last row in the range of 'buys' relevant to that 'sell'.
=IF($B2>=0,"",LARGE(IF($B$2:$B2>0,ROW($A$2:$A2)),1))
In column G there's a normal formula to capture the row number of the first row in the range.
=IF(ROW()=2,ROW(),IF(B2>0,IF(B1<0,ROW(),""),""))
In column H, convert this to be stored in the relevant 'sell' row using an array formula:
=IF($B2>=0,"",LARGE(IF($G$2:$G2>0,$G$2:G2),1))
In column E, balance, use these calculated row range references in an INDIRECT statement to calculate the balance.
=IF(B2>0,"",(C2*-(B2))-(-(B2)*(SUMPRODUCT(INDIRECT("B"&H2&":B"&F2),INDIRECT("C"&H2&":C"&F2)/SUM(INDIRECT("B"&H2&":B"&F2))))))
Note that INDIRECT uses a string to reference cells and ranges and if you move cells or ranges you will have to manually change the INDIRECT string to reference the correct cells.
Responding to #carol, and looking at the Q&A again, specifically where you say " although the problems comes up after because it needs to ignore the balances that came before José and start with the new ones that follow up," I realize that you may be looking to instead display the balance of all sales receipts and purchases since the last sale. If so:
In Cell G2: =F2
Do not copy down the above. Do copy down those below.
In Cell E2: =IF(B2<0,G2,"")
In Cell F2: =B2*C2
In Cell G3: =IF(B2<0,F3,F3+G2)
I saw an solution where someone was using a range as the criteria for COUNTIF and while trying to understand it better I found some really odd things happening and hoping someone could explain to me what is going on. Here is the setup of the excel.
Name,,Name
Excitebike,,Excitebike
RC Pro Am,,Super Mario Brothers
Punch Out,,Duck Hunt
Super Mario Brothers
Duck Hunt
Hopefully you can use the above to copy and paste it in. In column A there is a list of names and in column C there is a list of some of the names. In cell E1 there is a formula:
=COUNTIF($C$2:C4,$A$2:$A$6)
Then in cell E2 there is the exact same formula.
=COUNTIF($C$2:C4,$A$2:$A$6)
Here is a screen shot so you can see the formulas are identical:
So cell E1 and E2 have the exact same formula but are giving me a different result. As you can see in the first screen shot cell E1 gives a result of 0 while E2 gives a result of 1. Then if I make cell E1 into an array formula it gives a result of 1.
Why would the exact same formula in two different cells give a different result and why when changing cell E1 to an array formula would it change the result? I am using Excel 2016.
UPDATED: Additional questions.
When passing in a array into COUNTIF does it check each element in the range against each element in the criteria or does it just check row in the range against the corresponding row in the criteria?
Even when I put them in the same order, I cannot get the COUNTIF to return a number greater then 1. I would expect if the first 3 match the COUNTIF should return 3 but it is returning 1 for me. Please see below:
While rows 2, 3 and 4 match it is still giving an answer of 1.
I was a little surprised this worked at all. Typically I've used the "criteria" as >4 or <10 etc. Nice to know you can do a string comparison at all.
When using CountIf outside of an array formula you're going to be getting a comparison of values in adjacent cells. Typically CountIF is looking for a single criteria, not a range. At least that's the way I've always used it. eg, first formula in the cell range compared to first cells in each of the cell ranges.
Try these two experiments. Copy Super Mario Brothers from the right column to the left column and the results are going to now show 1 and 1 in the two formulas. Put it back. Move the two cells you have formulas in down one row, and you should see the results go from 1 and 0 to 1 and 1. Move it one more cell lower and it changes the values again.
I'm not sure this is what you're trying to accomplish, but copy this into the formula at and then copy down 6 rows. =COUNTIF($A$2:A$6,C2)
If it is possible, I'd like to create a formula that will allow me the following:
Formula must be in the entire column or in this example, in the range B1:B5. The formula is based on a condition, that when the total sum of cells from column A is lower D1, than it gives "X". If the total sum is over D1, then it gives an empty field - "".
In this example the total sum of the cells, that are over D1 value is in the first 3 rows, hence the three X-es, and then it stops.
(source: shrani.si)
.
I presume it would be possible to do this with multiple SUMIF commands, but does anyone know a smoother solution for this?
Thanks!
You can do this easily by using an absolute reference for the starting point of a SUM and using a relative reference for the end point. When copied down, this formulas works fine.
=IF(SUM($A$1:A1)<$D$1,"x","")
Results
Try this
=IF(SUM(OFFSET(A1,0,0,$A$1:A1,1))>$D$1,"X","")
This formula should start at B1 and then you use auto-increment to populate other cells
I have the following summation formula:
In text:
SUM (k*1.07^n), n=c1 to n=c2
k, c1 and c2 are 3 single numbers, specified in respective individual cells.
k is a constant, but c1 and c2 should be dynamically changeable.
Is that possible to do in Excel, and if so, how?
I know it's a fairly simple mathematical concept so I'd be surprised if Excel couldn't do it, but I haven't been able to find the formula myself. I've tried SUM and SUMIF, but from what I understand, that requires me to fill a whole range of cells each time I want to calculate something. I've also found some suggestions to use arrays in Excel, which I understand is automatically filling cells - which is at least a little more automated - but I'd rather not fill extra cells, if it's possible.
As a sidenote, I read Excel's accuracy is bad in high digit numbers, but as long as the first 5 digits are correct, it'll be accurate enough for my purpose.
With k, c1, and c2 in A1, B1 and C1 respectively, use the following formula:
=A1*SUMPRODUCT(1.07^ROW(INDIRECT(B1&":"&C1)))
Regards
I am building an excel formula, where i want to do something like below
Suppose i have 10 rows in excel sheet
I have values in B1 to B9, i want to create a formula so that sum is shown in C10.
I know it is simple =SUM(B1-B10) but only in case when number of rows are fixed.
Whereas in my case, i also want this relation to work if i keep on adding any number of rows, so
C(n) should always give a sum of B(1) to B(n-1)
I have tried indirect but not able to use it convincingly
Try this in C10
=SUM(OFFSET(B$1,0,0,ROW()-1,1))
Assuming you fix C1=0, the formula you should use is
[C2] =OFFSET(C2,-1,-1)+OFFSET(C2,-1,0)
and fill down.