Sheets is treating "0" like a blank cell - if-statement

I need help with what I'm sure is a simple formula that I just don't understand.
I have three columns. The first two hold my values and the third is meant to subtract them. However, when the first column is blank, I would like the third to also be blank. I have it close right now but when I type 0 in the first column, it treats that as a blank cell instead of using the 0 to give the sum.
Ex. of what I would like
expected result:
I can't seem to figure out the formula for the third column.

Yes this is a quirk that goes right back to the dawn of spreadsheet applications; in an empty worksheet the formula =A1 written anywhere other than the top left cell will evaluate to 0.
One way, in Google Sheets, is to use something like
=IF(ISBLANK(A1), ,A1 - B1)
In Microsoft Excel you need to use double quotations characters in the second argument, noting that this injects a blank string into the output.

This if statement (put in the 3rd Column) checks the first column if blank then just set cell as blank else perform the subtraction:-
=IF(A1="", "", A1-B1)

Related

In Google Sheets IF formula over several cells

I'm not sure if I'm approaching this problem wrong, but there's got to be an easy way to do this.
I simply want to see if Certain text is listed above that cell. If it's not, Put that text. If it is put blank.
This is what I have:
=if(F4:F5="TEST","","TEST")
This gives it an array formula error so I created this:
=arrayformula(if(F4:F5="TEST","","TEST"))
But I don't need two results... just a yes/no statement. If the cells in this range contain "TEST" leave blank, if it does not contain "TEST" display the word "TEST".
What am I doing wrong?
If the cells in this range contain "TEST" leave blank, if it does not contain "TEST" display the word "TEST".
Use COUNTIF()
=if(countif(range,"TEST"),,"TEST")

Find "real" formula for a formula group

I am trying to find the "real" formula of a group. For example, these are the formulas
=If(A$4>$A1,"Long","Short")
=If(B$4>$A1,"Long","Short")
=If(A$4>$A2,"Long","Short")
=If(A$4>$A$2,"Long","Short)
The forth formula is a different one. The first 3 formulas should be the same formula that is a cell fixed 4th row compare to a cell fixed at column A. The result should show 2 "real" formula. Something like this
=If($4>$A,"Long","Short")
=If($4>$A$2,"Long","Short")
How do I design a regex (or any other method) in VBA to extract that "real" formula from the "nominal" formulas?
Convert your formulas to display in R1C1 format by using File,Options,Formulas and ticking R1C1 style. In such a style your four example formulas would display (If they were entered in column 3) as
=IF(R4C[-2]>RC1,"Long","Short")
=IF(R4C[-1]>R[-1]C1,"Long","Short")
=IF(R4C[-2]>R[-1]C1,"Long","Short")
=IF(R4C[-2]>R2C1,"Long","Short")
The fixed portions of the addresses don't have braces [] so if you remove the braces and their contents you get
R4C>RC1
R4C>RC1
R4C>RC1
R4C>R2C1
and no 4 is different from the others

Best way to show blank cell if value if zero

=COUNTIFS(Orders!$T:$T,$B4)
is a code that gives 0 or a +ve result
I use this across 1500 cells which makes the sheet gets filled with 0s
I'd like to remove the Zeros by using the following formula
if(COUNTIFS(Orders!$T:$T,$B3,Orders!$F:$F,""&P$1&"*")=0,
"",
COUNTIFS(Orders!$T:$T,$B3,Orders!$F:$F,""&P$1&"*"))
This calculates every formula twice and increases the calculation time.
How can we do this in 1 formula where if the value is 0 - keep empty - otherwise display the answer
I suggest this cell-function:
=IFERROR(1/(1/COUNTIFS(Orders!$T:$T,$B4)))
EDIT:
I'm not sure what to add as explanation. Basically to replace the result of a complex calculation with blank cells if it results in 0, you can wrap the complex function in
IFERROR(1/(1/ ComplexFunction() ))
It works by twice taking the inverse (1/X) of the result, thus returning the original result in all cases except 0 where a DIV0 error is generated. This error is then caught by IFERROR to result in a blank cell.
The advantage of this method is that it doesn't need to calculate the complex function twice, so can give a significant speed/readability increase, and doesn't fool the output like a custom number format which can be important if this cell is used in further functions.
You only need to set the number format for your range of cells.
Go to the menu Format-->Number-->More Formats-->Custom Number Format...
In the entry area at the top, enter the following: #;-#;""
The "format" of the format string is
(positive value format) ; (negative value format) ; (zero value format)
You can apply colors or commas or anything else. See this link for details
instead of your =COUNTIFS(Orders!$T:$T,$B4) use:
=REGEXREPLACE(""&COUNTIFS(Orders!$T:$T,$B4), "^0$", )
also, to speed up things you should avoid "per row formulae" and use ArrayFormulas

How do I apply a formula to a range without applying said formula to every cell?

I'm trying to apply a formula without having it add the formula data to each and every cell - in other words, I need the cells that are receiving the formula to be untouched until they get their data.
I was searching around and it looked like an ARRAYFORMULA would work but it doesn't seem to be doing anything when I apply it.
For example, I want to apply this formula to a cell range: =SPLIT(E2, ",")). Each cell in the E column needs to be split into two the two adjacent cells next to it based on it's comma. When I try to apply =ARRAYFORMULA(SPLIT(E2:E99, ",")) only the cell I add this to gets the formula.
In addition to the contribution of pnuts, also try:
=ArrayFormula(iferror(REGEXEXTRACT(","&E2:E,"^"&REPT(",+[^,]+",COLUMN(OFFSET(A1,,,1,6))-1)&",+([^,]+)")))
Note: the last parameter of OFFSET can be changed to match the maximum number of values you have in the cells of the range E2:E (separated by a comma). E.g: if you have a no more than 3 values per cell, set it to three. The output will then be three columns wide (one column for each value).
Hope that makes sense ?
Also credits due to AdamL who (I believe) orginally crafted this workaround.
I think what you want may be array_constrain but for your example I can only at present offer you two formulae (one for each side of the comma):
=Array_constrain(arrayformula(left(E2:E,find(",",E2:E)-1)),match("xxx",E:E)-1,1)
=Array_constrain(arrayformula(mid(E2:E,find(",",E2:E)+1,len(E2:E))),match("xxx",E:E)-1,1)

Conditional Vlook up without using VBA

I want to convert an input to desired output. Kindly help.
In the output - the columns value should start from most recent (year)
Please click this to see data
Unfortunately VLOOKUP is not able to fulfill that ask. However the INDEX-function can.
Here is a good read on how to use it:
http://fiveminutelessons.com/learn-microsoft-excel/use-index-lookup-multiple-values-list
This will work for you spreedsheet, if your input table starts at A1 without a header and your output table starts at H3 with the first ID.
You get this by copy&pasting the first column of your input table to column H and then remove duplicates.
{=IF(ISERROR(INDEX($A$1:$C$7,SMALL(IF($A$1:$A$7=$H$3,ROW($A$1:$A$7)),ROW(1:1)),3)),"",
INDEX($A$1:$C$7;SMALL(IF($A$1:$A$7=$H$3,ROW($A$1:$A$7)),ROW(1:1)),3))}
Let's look at the formula step by step:
The curly brackets tell excel that this is an array formula, the interesting part for you is: when you've inserted the formula (without curly brackets) press shift+ctrl+enter, excel will then know that this is an array formula.
'error at formula?, then blank, else formula
=IF(ISERROR(....),"",...)
When you autofill this formula you probably dont know how many instances of your lookup variable are. So when you put this formula in 4 cells, but there are only 3 entries, this bit will keep the cell blank instead of giving an error.
INDEX($A$1:$C$7,SMALL(IF($A$1:$A$7=$H$3,ROW($A$1:$A$7)),ROW(1:1)),3))
$A$1:$C$7 is your data matrix. Your IDs (in your case 125 and 501) are to be found in $A$1:$A$7. ROW(1:1) is the absolute(!) rowID, 3 the absolute(!) column id. So when you move your input table those values have to be changed.
What exactly SMALL and INDEX do are well described in the link above. (Or at least better than I could.)
Hope that clarified some parts,
Tom