Excel sum two non-adjacent cells ignoring NA error - sum

This is really simple, but I can't find the correct solution.
I have two cells A1 and D1 that I need to add together, however one or both of them may contain NA errors (to prevent plotting on a graph). I need to find the total of these two cells, or if one is NA it must return the non-NA value :
eg : 100+NA=100 or NA+100=100 or 100+100=200
I have tried =SUMIF(Range_1,"<>#NA") but as this is not a range I can't get the right answer and I have tried combinations of if(iserror formula with no success... help !!

Good thing that you found a solution yourself.
An even easier way (IMHO - from a legibility point of view) might be to use
=IFERROR(A1; 0) + IFERROR(D1; 0)
This way you still perform a simple addition operation, but include the required conditionality.
IFERROR() is a convenience function that combines the functionality of the IF() function and the ISERROR() function; it avoids having to state the same formula twice when using only the IF() function.

I found the =IFNA formula to work faster.
In your example, it would be =IFNA(A1,D1) - if A1 is not NA it'll return the value, otherwise will return D1. It means that if both A1 and D1 are NA, that will be the output.
Hope this helps!

Related

sumproduct function in apache poi (version 3.15) with if condition is not working

I'm using below formula to calculate sum product with if condition using Apache poi 3.15 version, but it's not evaluating with if condition (--(A1:A6="A")) and its giving "#VALUE" error.
The same formula if i use directly in excel, its working as expected. and if I remove "--(A1:A6="A")" this condition, it works fine with poi.
Formula:
=SUMPRODUCT(--(A1:A6="A"),B1:B6,C1:C6)
Could you please tell me how to evaluate this kind of formula or is there any alternative way to evaluate this?
Okay, sorry for originally barking up the wrong tree...
A fresh pair of Monday eyes and I can see the issue:
You are using quotes " inside a quoted string, you need to escape the quotes in the formula with \ - cell.setCellFormula("SUMPRODUCT(--(A1:A6=\"A\"),B1:B6,C1:C6)");
=SUMPRODUCT(--(A1:A6="A")*(B1:B6)*(C1:C6)) - Edited to desired logic
By using the double unary "--" you convert true/false in to 0 or 1.
This is an if condition, so you need to also multiple each row of data by the 0 or 1 and sum the result; when the condition is false the product of the row will multiply by 0 giving a total of 0 to be summed for that row.
The issue is not with the formula, it's with the workbook which I'm using. The workbook SXSSFWorkbook has an issue with evaluation. When I changed to XSSFWorkbook, it started evaluating properly.
I suggest using either XSSFWorkbook(.xlsx) or HSSFWorkbook(.xls) in order to make the formula work properly.
=SUMPRODUCT(B1:B6,C1:C6,--(A1:A6="A"))
Note: Do not put IF condition (--(A1:A6="A")) as first argument.
Thanks

Splitting information from a cell

My sheet contains three types of cells:
5off
50off
550off
What they should read is:
$5.00 Off
$0.50 Off
$5.50 Off
I've been fighting with Text-to-Columns and =concat for a while and am trying to get this to work as easily as possible. Any ideas?
Just wondering what's the rule of the conversion for example the first figure is
5off => "$5.00 Off" > split number, add decimal, upper the O in off, concatenate
However in number two the rules are a little different
50off => "$0.50 Off" > split number, make the number decimal, concatenate
Based on those limited information I will suggest you to break down your problem to simpler form:
See image below, the top is the result, bottom is the formula used. There might be simpler way though.
Hope this help

Enter date into function without quotes, return date

I'm trying to write a function of this form:
Function cont(requestdate As Date)
cont = requestdate
End Function
Unfortunately, when I enter =cont(12/12/2012) into a cell, I do not get my date back. I get a very small number, which I think equals 12 divided by 12 divided by 2012. How can I get this to give me back the date? I do not want the user to have to enter =cont("12/12/2012").
I've attempted to google for an answer, unfortunately, I have not found anything helpful. Please let me know if my vocabulary is correct.
Let's say my user pulled a report with 3 columns, a, b and c. a has beginning of quarter balances, b has end of quarter balances and c has a first and last name. I want my user to put in column d: =cont(a1,b1,c1,12/12/2012) and make it create something like:
BOQ IS 1200, EOQ IS 1300, NAME IS EDDARD STARK, DATE IS 12/12/2012
So we could load this into a database. I apologize for the lack of info the first time around. To be honest, this function wouldn't save me a ton of time. I'm just trying to learn VBA, and thought this would be a good exercise... Then I got stuck.
Hard to tell what you are really trying to accomplish.
Function cont(requestdate As String) As String
cont = Format(Replace(requestdate, ".", "/"), "'mm_dd_YYYY")
End Function
This code will take a string that Excel does not recognize as a number e.g. 12.12.12 and formats it (about the only useful thing I can think of for this UDF) and return it as a string (that is not a number or date) to a cell that is formatted as text.
You can get as fancy as you like in processing the string entered and formatting the string returned - just that BOTH can never be a number or a date (or anything else Excel recognizes.)
There is no way to do exactly what you're trying to do. I will try to explain why.
You might think that because your function requires a Date argument, that this somehow forces or should force that 12/12/2012 to be treated as a Date. And it is treated as a Date — but only after it's evaluated (only if the evaluated expression cannot be interpreted as a Date, then you will get an error).
Why does Excel evaluate this before the function receives it?
Without requiring string qualifiers, how could the application possibly know what type of data you intended, or whether you intended for that to be evaluated? It could not possibly know, so there would be chaos.
Perhaps this is best illustrated by example. Using your function:
=Cont(1/1/0000) should raise an error.
Or consider a very simple formula:
=1/2
Should this formula return .5 (double) or January 2 (date) or should it return "1/2" (string literal)? Ultimately, it has to do one of these, and do that one thing consistently, and the one thing that Excel will do in this case is to evaluate the expression.
TL;DR
Your problem is that unqualified expression will be evaluated before being passed, and this is done to avoid confusion or ambiguity (per examples).
Here is my method for allowing quick date entry into a User Defined Function without wrapping the date in quotes:
Function cont(requestdate As Double) As Date
cont = CDate((Mid(Application.Caller.Formula, 7, 10)))
End Function
The UDF call lines up with the OP's initial request:
=cont(12/12/2012)
I believe that this method would adapt just fine for the OP's more complex ask, but suggest moving the date to the beginning of the call:
=cont(12/12/2012,a1,b1,c1)
I fully expect that this method can be optimized for both speed and flexibility. Working on a project now that might require me to further dig into the speed piece, but it suits my needs in the meantime. Will update if anything useful turns up.
Brief Explanation
Application.Caller returns a Range containing the cell that called the UDF. (See Caveat #2)
Mid returns part of a string (the formula from the range that called the UDF in this case) starting at the specified character count (7) of the specified length (10).
CDate may not actually be necessary, but forces the value into date format if possible.
Caveats
This does require use of the full dd/mm/yyyy (1/1/2012 would fail) but pleasantly still works with my preferred yyyy/mm/dd format as well as covering some other delimiters. dd-mm-yyyy or dd+mm+yyyy would work, but dd.mm.yyyy will not because excel does not recognize it as a valid number.
Additional work would be necessary for this to function as part of a multi-cell array formula because Application.Caller returns a range containing all of the associated cells in that case.
There is no error handling, and =cont(123) or =cont(derp) (basically anything not dd/mm/yyy) will naturally fail.
Disclaimers
A quick note to the folks who are questioning the wisdom of a UDF here: I've got a big grid of items and their associated tasks. With no arguments, my UDF calculates due dates based on a number of item and task parameters. When the optional date is included, the UDF returns a delta between the actual date and what was calculated. I use this delta to monitor and calibrate my calculated due dates.
All of this can absolutely be performed without the UDF, but bulk entry would be considerably more challenging to say the least.
Removing the need for quotes sets my data entry up such that loading =cont( into the clipboard allows my left hand to F2/ctrl-v/tab while my right hand furiously enters dates on the numpad without need to frequently (and awkwardly) shift left-hand position for a shift+'.

Need Help In Making a Dynamic Formula in LibreOffice/Excel

I need help making a dynamic formula and I'm not sure how to do it. Here is my structure.
A4=1
B4=0
C4=1
D4=SUM(A4+B4+C4)
H4=(A4-C4)/D4*100
Now we come to cell J4. What I need J4 to do is this: If H4 is less than 78%, I want it to tell me how many more I need in cell A4 to show a value of 78% or higher in cell H4. This is a Sample Formula I have, but it's not correct.
=IF(H4>=0.78,"You 're fine","You Need "&INT((SUM(A4:C4)*0.78+H4)/0.22)&" to get to 78%")
Try this:
=IF(H4>=78,"OK",CONCATENATE("You need ",INT((A4/H4)*(100+H4))," to get to your goal"))
Test Values:
A4=100
B4=0
C4=56
Sums:
D4= 156
H4=28
Maybe this would suit:
=IF(H4<78,"You Need "&ROUNDUP((89*C4+39*B4)/11-A4,2)&" to get to 78%","You're fine")

pentaho report designer libFormulaErrorValue

I have a formula that takes value from query data
Now, I want to skip the formula if the query data is 0
Example: [value1]-[value2]/[value1]*100
If the [value1] is 0, skip the formula.
First of all, Pentaho Report Designer have build-in Formula Editor, which can greatly simplify your life when constructing these formulas. Not sure starting which version it available, but in 3.6.1 it's for sure.
Also in Pentaho Wiki you may find a useful page describing Formula Expressions: http://wiki.pentaho.com/display/Reporting/Formula+Expressions
As for your particular issue, I think this formula should work:
=IF([value1] = 0; ""; [value1]-[value2]/[value1]*100)
Starting equal sign is required in each formula!
By observing your formula, [value1] field is there in the denominator, there might be a chance to get zero(0) for that field. This is logical error.
If you handle that one, you can overcome this error.
For your case this formula would work.
= ( [value1]-[value2]/ IF(OR(ISEMPTYDATA([value1]); [value1] = 0) ;1;[value1]) )*100
I had an error where I used one date type as type "Date" and another as "Date(SQL)" where I used the first parameter with format "Date" to derive the other parameter with format "Date(SQL)" through a formula. Which came back to bite me.