In Excel I'm trying to compute a value which depends on other range value. I have a very strange problem: the same formula with different value doesn't work for some case.
This formula works:
ROUNDUP(AVERAGE(IF(RangeName1=1;RangeName2));2)*100&" %."
This one doesn't:
ROUNDUP(AVERAGE(IF(RangeName1=2;RangeName2));2)*100&" %."
I check and my RangeName1 does contain these values: 1 and 2 (order like this).
Does anybody has an idea why the second formula doesn't work?
When I try your formula's both work fine.
Can you tell us what you are trying to achieve?
If you want to display percentage in a cell you could also use cell formatting, this way your cell will only contain the actual number displayed in a certain way instead. see http://www.excel-easy.com/basics/format-cells.html for reference.
Just curious on excel to search for a value and return the address/location of the cell. For example if i had B9= 5 and used vlookup to find 5 rather than returning the value i would like B9 returned. Also in this case how do i use that reference for another formula rather than the actual value within the cell. Using an example again i would like my next formula to click on the value 5 cell but rather than using 5 in the formula to use the B9 cell reference. Is there anyway to do this? Ive tried using indirect, vlookup, match index etc and no luck.
First question:
If you insist on VLOOKUP(), it gets cumbersome:
Create an auxiliary column C with this: =CELL("address";B1)
Now you can use =VLOOKUP(5;B:C;2;FALSE) and you should get $B$9
If you just want to know "In which cell is the value 5?" you can use #Jeeped's solution: =ADDRESS(MATCH(5,B:B,0),COLUMN(B:B),4) (note that the value 5 is hardcoded here). You should get B9
If you already know the column (i.e. B) your question is "In which row is the value 5?" Answer: =MATCH(5;B:B) which gives you 9. To prepend B, use ="B"&MATCH(5;B:B)
Second question:
I guess you're looking for INDIRECT(). If you write one of the above formulas in, say, D1 (or even type in "B9" by hand into D1), you can use =INDIRECT(D1). This transforms the string "B9" back into a cell reference, which means you get B9's value back, i.e. 5
I have read http://poi.apache.org/spreadsheet/eval.html but I dont get it to work ...
I have a column in my sheet that contains these values:
D+1 (pseudo-formula, to be evaluated in java)
01.01.0001 (string constant)
=A1 (formula where A1 contains pseudo formula 'D+2')
=A2 (formula where A2 contains '13.08.2013')
(For strings like "D+1" I have written a parser that replaces D by todays date and increments it by one. "01.01.0001" is a magic value. "=A3" is obviously an excel formula )
How can I safely get all these values to a plain old java string that
dereferences excel formulas before
leaves pseudo formulas intact
treats everything else as string
???
so for above example I want to get:
"D+1"
"01.01.0001"
"D+2"
"13.08.2013"
If you're doing it by hand: You need to check both getCellType() and getCachedFormulaResultType(). The type will let you work out what kind of cell it is, for formatting / cell value fetching etc. For formulas, when you see it's a formula cell, you can then fetch the last evaluated value and the type of that
However, based on what you want, I think there might be a much simpler way to go. I think you can probably use DataFormatter, specifically formatCellValue(Cell)
If you use DataFormatter, it'll identify the type (including formulas), fetch the value, fetch the Excel-applied number/date formatting rules, and apply those. You get back a String which is the closest Apache POI can manage to what's shown in Excel, which looks like what you want
Can't believe I don't know this, but is there a way to avoid repeating a formula in an if statement if the logical test is dependent on it?
i.e.
=IF((SUMIFS formula)=0,"",SUMIFs formula)
I want to replace that SUMIFS function in the false scenario with something short that will tell it to just programmatically repeat the formula it originally tested for. Repeating the formula twice has to have detrimental effects on processing speed. Negligible, maybe, but want to go for best-practices here. Thanks.
You can force an error like #DIV/0! and then use IFERROR, e.g.
=IFERROR(1/(1/SUMIFS_formula),"")
You can assign a Name to a formula and use the Name..............See:
Assigning a name to a formula
Relevant excerpt -
For example, let's suppose we frequently use a formula like:
=SUM(A1:A100)-SUM(B1:B100) and this resides in A101 and is copied across many columns on row 101. It would be better in this case to
create a custom formula that does this in each cell on row 101. Here
is how;
1) Select cell A101 (this is vital).
2) Go to Insert>Name>Define and
in the "Names in workbook" box type: SalesLessCosts
3) Now click in
the "Refers to" box and type: =SUM(A1:A100)-SUM(B1:B100) then click
Add.
Now you can replace the formula in cell A101 with: =SalesLessCosts.
You can also copy this across row 101 and it will change its relative
references just as the formula =SUM(A1:A100)-SUM(B1:B100) would. The
reason it does this is all down to the fact we selected A101 before
going to Insert>Name>Define and used relative references in
=SUM(A1:A100)-SUM(B1:B100) when we added it to the "Refers to" box.
If all you need to do is hide zeroes, there is an easy way:
Select all cells where you wish to hide zeroes
Go into Custom Number Formatting
Set format to "General;General;"
The custom formatting has a structure of [positive numbers];[negative numbers];[zeroes]
By making the last part blank you are effectively hiding zeroes, but showing everything else.
The advantage over conditional formatting is that you can use this on any background.
A neat trick which I sometimes use is to hide the cell value completely by using a custom format of ";;;". This way you can put images inside the cells, like the conditional formatting ones, and not see the value at all.
Try using the SUBSTITUTE function like this :
=SUBSTITUTE( VLOOKUP( H4; $D$5:$E$8; 2; 0 ); $H$1; $I$1 )
Here is an example:
Here the formula I don't want to repeat twice is the VLOOKUP function.
The result of VLOOKUP is a string found in another table (ex : "Green").
I want to check if that string matches a specific string value in $H$1 (here, "Yellow").
If it does, SUBSTITUTE replaces it with$I$1 (the error string you want. Here, "FORBIDDEN").
If it doesn't, it displays the VLOOKUP result string (the normal authorized output, like "Green").
This is useful for me because my actual formula is quite long, so I don't want to write it twice.
I also dont want to use two different cells, because I'm already applying this formula on 10 columns, meaning I should add an extra 10 columns to make it work.
In some scenarios, MAX() or MIN() can do a wonderful job.
E.g., something like this:
=IF(SUMIFSformula>0,SUMIFSformula, 0)
Can be shortened to this:
=MAX(0,SUMIFSformula)
The LET formula can be used for this exact scenario. You can define the formula as a variable and then within that same cell you can reference the variable in your formula.
The LET formula format looks like this:
=LET(name,name_value,calculation)
SUMIFS Example
Here's how it would work with your SUMIF example so that you don't have to repeat the formula:
In this screenshot we have an array A1:B7. We want to sum the values (Col B) if the name in ColA is "apple".
For this we have a standard SUMIFS formula of
=SUMIFS(B1:B7,A1:A7,"apple")
The formula is showing in E2. The result is shown in E3.
To put this into the IF statement without having to repeat the formula we can use LET as shown in the screenshot.
We create a variable with the SUMIFS formula as the value of that variable. We then write our IF statement using the variable name instead of rewriting the formula multiple times.
=LET(name,name_value,calculation)
Variable name: sumapples
Variable value: SUMIFS(B1:B7,A1:A7,"apple")
Calculation: IF(sumapples=0,"",sumapples)
Put together in the LET function it looks like this:
=LET(sumapples,SUMIFS(B1:B7,A1:B7,"apple"),IF(sumapples=0,"",sumapples))
This LET function can be used in any Excel formula, and is very useful for shortening long formulas that have repetition.
Optional: Extra complexity
If you want to you can get extra complicated by naming multiple variables.
=LET(name,name_value,name2,name_value2,calculation)
Since Excel 2007, the IFERROR statement does what the OP asked. From the help file:
Description:
Returns a value you specify if a formula evaluates to an error; otherwise, returns the result of the formula. [italics mine]
Syntax:
IFERROR(value, value_if_error)
I've since realised that this was already answered by #barry houdini above.
Here is a hack - depending on whether you are just interested in the displayed value, or whether you need to use the value in another formula:
Put your SUMIF formula in the cell (without the IF part)
Create a conditional formatting rule which sets the font color to the background color when the cell value is 0
And hey presto, you get the desired result.
As I said - it's a hack, but it does prevent the double evaluation.
There is no "clean" solution that I am aware of.
I have a column of codes and I specifically want to extract ANY of these codes with Excel's IF function.
I wrote this code and it did not work: =IF(OR(O2={"6122";"6124";"6200";"6197"});1;0)
How can I use the IF function or other function to pick out any of the above codes?
EDIT: the code itself works but it does not return 1 when it hits any of the specified codes.
Check the value in cell O2. If it is text, then your formula will work. If the value in cell O2 is a number like 6122, then your formula will not work, since it is explicitly looking for a text value of "6122" and the other text values.
Data type matters. The text "6122" is not the same as the numeric value 6122.
You can alleviate the issue by coercing the value in O2 to a number and forcing a numeric comparison with
=IF(OR(O2+0={6122,6124,6200,6197}),1,0)
(if your regional settings use the semicolon ; as a list separator, please replace the commas in the above formula with semicolons)
This will work if O2 is either text or numeric. The values to compare with are numbers.
So, determine what data type is stored in cell O2 and make sure that you compare it with a suitable data type in your formula.