What is wrong with my formula - excel

I have been working on an EXCEL formula and am stuck.
=If(B10<4, B10*0, If(B10>3 AND B10<8, B10*1, B10*2)))
I keep getting an error. Can someone tell me what is wrong with it.
What I am trying to do is say:
If B10 is Less than 4 Multiply the value of B10 by Zero
If B10 is Between 4 and 7 Multiply the value of B10 by 1
Else Multiply the Value of B10 by 2

AND, is AND(condition1,Conditon2) not condition1 AND Condtion2
=If(B10<4, B10*0, If(AND(B10>3, B10<8), B10*1, B10*2))
That being said you do not need the AND at all:
=If(B10<4, B10*0, If(B10<8, B10*1, B10*2)))
The second if will fire only if B10 >= 4 so the B10>3 is not needed.
And since anything multiplied by 0 is 0 you do not need the B10*0. And since anything multiplie by 1 is itself, you do not need the *1
=If(B10<4, 0, If(B10<8, B10, B10*2)))
Credit #BruceWayne.

Looks like you have one too many parentheses. should look something like
=If(B10<4, B10*0, If(AND(B10>3, B10<8), B10, B10*2)))
This formula takes the and statement and places it inside of the second If statement, checking to see if the cell B10 is greater than or equal to 4 and then checking to see if the cell B10 is both less than 8 or greater than 3.

Can be shortened to =B10*((B10>=4)+(B10>=8))

Related

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.

Excel: How ro write Mutiple IFs in in same formula and formula not pulling correct value?

I am having trouble with the formula below as it is not pulling the correct value or perhaps the formula needs to be tweaked.
=IF((AND(Sheet1!H10>65,D17>=65)),Sheet2!D$47,VLOOKUP(D17,Sheet2!$A$2:$K$51,4,FALSE))
What I am basically trying to do is if the value in H10 is greater than 65 and the value in D17 > or = 65 then pull the value from sheet2 D47 cell. Other wise use vlookup to lookup the value.
I have a case where The value in D17 =66 however, it is returning the value based on the vlookup and not Sheet2-D47.
Also, is it possible to have multiple IFs in the same formula?
Where are you writing the formula? If your formula isn't on sheet1 D17 might be pointing at the wrong cell. It sounds like it would be pointing to the correct D17 if your vlookup is working though. Remember with an AND formula, all conditions need to be true. Is H10>65? if not then even with D17 = 66 then if statement will return false and execute the vlookup.
And yes you can have nested if statements (I believe 7 is the most). but you can do:
=if(A5>5, if(A5 = 7, "A5 is greater than 5 and equals 7", "A5 is greater than
5, but does not equal 7"),"A5 is less than 5)

OFFSET function

I have the following formula in a cell:
=IF(Q12,ROUND(SUM(Q12:Q18)/7,2),"")
Now when I drag it down I want it to calculate SUM for Range Q19:Q25 i.e it should be;
=IF(Q19,ROUND(SUM(Q19:Q25)/7,2),"")
I believe OFFSET is the function to add in the formula but I am not sure how to do it.
You are correct, OFFSET will do this job nicely, but in writing your answer, I have had to make a consideration to the fact that I don't know what offset your formula is to the sum range!
This will do the job, and if your formula isnt in row 1, you'll need the change both of the row() - 1 statements to offset the formula back to 0 (i.e. if this formula starts in row 12, change row() - 1 to row() - 12
=IF(OFFSET($Q$12,(ROW()-1)*7,0),ROUND(SUM(OFFSET($Q$12:$Q$18,(ROW()-1)*7,0))/7,2),"")
Having said all of that, you have a conditional (=If(Q12) and a sum pointing to the same place, shouldn't you be checking Q12 for some truth, then summing?
I don't know what your data set is though, so I could be talking rubbish.
Hope this helps!
Taking only the SUM part of your formula and assuming placed in Row1 please try:
=SUM(OFFSET(Q$12,7*(ROW()-1),,7,1))

Sum of numbers + 0

I am having a problem with a small number. I am using SUM function to sum certain numbers. If I add a zero to the range, it is not displaying zero. I don't know why.
A1
=SUM(B1:R1)*-1
C1 to L1
266864 -100000 -15136.15 -23688.82 -120870 -7169 -5550 1224 -0.03 4326
A2
=SUM(B2:R2)*-1
C2 to M2
=SUM(C3:C3) =SUM(D3:D3) =SUM(E3:E3) =SUM(F3:F3) =SUM(G3:G3) =SUM(H3:H3) =SUM(I3:I3) =SUM(J3:J3) =SUM(K3:K3) =SUM(L3:L3) =SUM(M3:M3)
A3
=SUM(B3:R3)*-1
C3 to M3
266864 -100000 -15136.15 -23688.82 -120870 -7169 -5550 1224 -0.03 4326 0
A1 is displaying 0, but A2 and A3 displays 9.09E-13
The number 9.09E-13 is another way (scientific notation) of saying 0.000000000000909495, a very small decimal number. What you are experiencing is a 15 digit precision floating point error.
    
Typically, you would use the ROUND function or something similar to remove the error (if you have to).
See Floating-point arithmetic may give inaccurate results in Excel for more information.
as I think,
might be some different formula on A1 cell is already placed or the type of A1 Cell is int and Value becomes in decimal or else, so make try this formula in different cell.
I wonder why you are using =SUM(C3:C3) etc. That is, Why use the sum function on a single cell. Unless there is a specific reason, I suggest you use = C3 instead. I've found that using the summation on a single cell can sometimes return answers that are incorrect. Don't know why, but it does. Therefore, long ago I quit using the sum unless there is a range that includes more than one cell.

Subtraction with blank cells - Excel

I created spreadsheet for budgeting purposes and have it set up so that every time I add some data in my income or expenses column, my balance column automatically posts a readjusted value. However, my formula only seems to work for positive values (see conflict on row 4 of example) Here's what I have so far, pasted in as an array formula in B3 and copied down.
=IF((ISNUMBER(C3:D3)),B2+C3-D3,"")
How could improve the "if true" section of my formula?
the problem you're having is your if statement will return false if either C or D is not a number. if(c through d is a number) will mean that it only is true when both are numbers.
If you want to make it so that you only evaluate numbers (and not treat blanks as 0), then you'll probably want to make an OR statement:
=IF(OR(ISNUMBER(C3),ISNUMBER(D3)),B2+C3-D3,"")
Just be aware that if the relative location of B2 is missing data (if you did not have any expense or income the previous day/week/whatever), then the next field will become a value error when you add something. So if B5 is empty because you didn't do any spending or gaining, then when you spend and put value in "expense" on D6, B6 will become #Value.
To fix this, it might be a good idea to finish off not with an empty string, but with the value of the previous date. It's up to you if you want to use it that way.
=IF(OR(ISNUMBER(C3),ISNUMBER(D3)),B2+C3-D3,B2)
You could try the following, applied on B3:
=IF(AND(ISBLANK(C3),ISBLANK(D3)),"",B2+C3-D3)
This way, you don't need an array formula - I'm just checking if C3 AND D3 are blank - if so, the cell will be empty, otherwise will do the math.
You could put an Or statement in so that if either C3 or D3 is a number, then calculate accordingly.
=IF(Or(ISNUMBER(C3),ISNUMBER(D3)),B2+C3-D3,"")

Resources