Excel Formula - IF & "X" > 0 - excel

I have a formula that I'm using in Excel to determine what the payback of a value is after "X" of months. But I'd like to modify the formula to display 0 or $0.00 if the result of the formula is less than $0.00
The current formula is
=C2-(C2*(G2/24))
But is there a way I can make this so once the value hits 0 or less than 0, it would simply display $0.00
Thanks,

For readability's sake you could also use:
=MAX(C2-(C2*(G2/24)),0)
That presents Excel with two options, the result of the formula or zero, and asks it to display the larger of the two.

You can use something like:
=IF(C2-(C2*(G2/24))>0,C2-(C2*(G2/24)),0)
to return a 0 result if the result would have otherwise been negative.

Related

Excel - standard deviation where source cells are a count

I have some data that looks like this
Condition 1
Condition 2
Condition 3
Condition 4
Condition 5
0
0
0
70
0
0
50
10
0
0
120
0
0
5
5
Where the value in each cell is the number of meters of an asset that is the given condition. Or in other words, a count of the number of meters that are a '4'.
How do I calculate a standard deviation for this? Obviously the std.dev would be '0' for the first row, higher for row 2, and fairly low for row 3.
Something similar to REPT, but that repeats a value x times in a formula?
I considered a helper column but the number of meters that there are in total makes this impractical.
I am not a math expert, but I can show you how to "make a range of numbers" based on the criteria shown, using Excel 365.
Suppose your data is in the range B2:F4 as shown below. In cell G2, enter the following formula and drag it down:
=STDEV.P(--FILTERXML("<t><s>"&TEXTJOIN("</s><s>",1,REPT($B$1:$F$1&"</s><s>",$B2:$F2))&"</s></t>","//s[number()=.]"))
The above will calculate the standard deviation using the STDEV.P function, but I am unsure if this is the right function to use as there are many other variations to the original STDEV function.
Regardless, the following part of the formula is able to return a range of numbers as desired:
=--FILTERXML("<t><s>"&TEXTJOIN("</s><s>",1,REPT($B$1:$F$1&"</s><s>",$B2:$F2))&"</s></t>","//s[number()=.]")
You can view this question and the answer by JvdV to understand the use of the FILTERXML function.
Another way of doing it is to use the alternative SD formula
which would give you
=SQRT((SUM(A2:E2*COLUMN(A2:E2)^2)-SUM(A2:E2*COLUMN(A2:E2))^2/SUM(A2:E2))/SUM(A2:E2))
for the population standard deviation.
The Excel 365 version using Let is more readable I think:
=LET(x,COLUMN(A2:E2),
mpy,A2:E2,
n,SUM(mpy),
sumxsq,SUM(mpy*x^2),
sumsqx,SUM(mpy*x)^2,
numerator,sumxsq-sumsqx/n,
SQRT(numerator/n)
)
A bit less obviously, you could get it from the original formula
=SQRT(SUM(A2:E2*(COLUMN(A2:E2)-SUM(A2:E2*COLUMN(A2:E2))/SUM(A2:E2))^2/SUM(A2:E2)))
Again, in Excel 365 you could write this as:
=LET(x,COLUMN(A2:E2),
mpy,A2:E2,
n,SUM(mpy),
xbar,SUM(mpy*x/n),
numerator,SUM(mpy*(x-xbar)^2),
SQRT(numerator/n)
)
Change the denominator to
(SUM(A2:E2)-1)
for the sample standard deviation.
I ended up figuring it out.
I added a column which calculated the average. (Say column F)
I then had a formula like this
=SQRT(SUM(A2*POWER((1-F2),2),B2*POWER((2-F2),2),C2*POWER((3-F2),2),D2*POWER((4-F2),2),E2*POWER((5-F2),2))/SUM(A2:E2))
Essentially this calculated the variance from the mean for each condition value, multiplied by the number of values (e.g. number of meters) of asset that are that particular condition, then did the normal other standard deviation calculations (sum, divide by total, square).

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.

I am trying to make a weekly projection using nested if in Excel

I have this statement in Excel (Nested IF)
=IF(E3-B3>0,E3-B3,IF(D3-B3>0,(D3-B3),IF(C3-B3>0,C3-B3," ")))
What I am missing is that he 250 value on the last Cell H3 (Dollars to Budget MTD) have to be calculated only (E3-B3)30-50 and returning -20 as a result. However, it is returning 250 which is wrong in my logic.
The 250 value on the last Cell H3 (Dollars to Budget MTD
) have to be calculated only 30 -50 = -20
It seems you want the last number in C3:G3 as the minuend, B3 as the subtrahend and the difference in H3. Try this in H3,
=index(B3:G3, match(1e99, B3:G3))-B3
'... for a running total then,
=sum(C3:G3)-B3
As soon as you fill in F3, either of the formulas will adjust.
Try this:-
I simply used a dummy value A in your formula which will never be true
=IF(E3-B3<>"A",E3-B3,IF(D3-B3<>"A",(D3-B3),IF(C3-B3<>"A",C3-B3," ")))

An Excel formula, find maximum and check for multiple conditions

I asked a similar question before this but it turned out that whatever formula I was using does not give me the correct result. So I have to reask the question and make it more specific.
Suppose I have the following spreadsheet:
I want a formula which gives me the latest date that have percentage change that is greater than zero and "Orange" is not mentioned in the "Comments" column. Only 1 of the percentage changes (Column Pct1 to Pct 5) needs to be >0. So the formula will output 11/20/2012 since it has % change that is greater than 0% and it is non-Orange.
I tried match, offset, max but it didnt give me the correct result. I am hoping to input this as a formula into VBA because I have a total of 20 excel files that I need to have the macro to check against. Please help me! Thanks!!
{=MAX((B2:F6>0)*(ISERR(FIND("ORANGE",UPPER(G2:G6))))*(A2:A6))}
Enter with Ctrl+Shift+Enter, not just Enter. Don't type the curly braces, Excel will insert them if you enter as an array formula.
The first section returns a matrix of TRUEs and FALSEs based on whether the percentages are greater than zero.
The second section returns TRUEs and FALSES based on whether FINDing "Orange" generates an error.
The last section returns an array of the dates.
When you multiply the arrays/matrices the TRUEs are 1, the FALSEs are 0 and you end up with an array of dates where all the conditions are TRUE. Finally, MAX picks the largest.

Different approach to my situation

on a excel sheet I've got columns, each column represents a weeknumber.
I want to calculate the so-called 4 wk average for each row and for each week and this is the formula I use:
((value*Tvalue)+(value*Tvalue)+(value*Tvalue)+(value*Tvalue))/(Tvalue) (this is not the actual formula but simplified, that's not really important).
It's the checks that make things a bit more complex. If a value of a weeknr is zero, skip it, but if the next value is also zero, just skip the formula alltogether and make it a zero (or text like "false"). So another thing that has to be accounted for is that if a value is zero, the next weeks value is taken instead.
Example (see included file):
I want to calculate the formula (mov 4wk avg) for the third value for week 12, which will make the formula (0.2*6)+(0.3*6) now there's a zero on week 14 so I skip it, then formula will be:
(0.2*6)+(0.3*6)+(0.6*6)+(0.9*6)/(6). Hope that made some sense.
Right now I'm doing this in VBA with a lot of variables and a lot of if statements.
Is there an easier more effective way to go about this?
Example sheet
https://dl.dropbox.com/u/3121767/Book1.xlsx
PS I know the example sheet is a 2007/2010 version but I need to accomplish this for 2003
Array formula could be used (Ctrl-Shift-Enter in formula window, curled brackets will be inserted by Excel itself, not by a user):
A3: T value for row 3
B3:E3: values for single weeks in row 3
={IF(OR(SUM(IF((B3:C3)=0;1;0))>1;SUM(IF((C3:D3)=0;1;0))>1;SUM(IF((D3:E3)=0;1;0))>1);"Fail";(B3*$A3+C3*$A3+D3*$A3+E3*$A3)/$A3)}
The formula takes pairs of weeks, if the sum of the pair is 0, the whole formula will fail. If there's only one zero, everything will remain the same, as 0*value is equal to skip.
The formula can be copied to the right and downwards.
The updated exampe is available at http://www.bumpclub.ee/~jyri_r/Excel/4_week_average.xls
I tried a 2-step approach
1) transform each cell according to following rules:
if myweek = 0 and mynextweek = 0 then
myweek = 0
elseif myweek = 0 and mynextweek <> 0 then
myweek = mynextweek
else
myweek = myweek
endif
in Sheet2!B2 I entered =IF(AND(Sheet1!B2=0,Sheet1!C2=0),0,IF(Sheet1!B2=0,Sheet1!C2,Sheet1!B2)) and copied to all cells where in Sheet1 dat aexists, together with a copy of the base value in column A
2) Then I create a standard moving average across 4 weeks, for each set of 4 columns, starting with W15 in column M ... matter of taste if you display this in Sheet1 or Sheet2

Resources