IFERROR not returning an array and thus breaking the SUMPRODUCT result - excel-formula

I have a column in a spreadsheet in which numbers are sometimes
stored in text format or are mixed with text values.
For converting them to numbers I would
normally use VALUE. And because of the other text values in the same column I would additionally wrap it
with IFERROR, defaulting the result to 0 to prevent any issues with the
conversion.
All this I wanted to use in SUMPRODUCT and I am reluctant to add any new intermediate columns to the sheet.
I face an issue with IFERROR returning a single value (or even a #VALUE! error) when it is used in SUMPRODUCT as one of the arrays. What's even worse, the sum is correctly assessed in the Function Arguments window.
I created an isolated case, that you can see here SUMPRODUCT using IFERROR problem. One of the numbers in column C is preceded with with single quotation "'" and the C column holds both text and number values.
A long version of the SUMPRODUCT formula
=SUMPRODUCT(IFERROR(VALUE($C1:$C4),0),--($D1:$D4="yes"),--NOT(ISERROR($C$1:$C$4+1-1)),--(($C1:$C4)<>"")) and the simplified one =SUMPRODUCT(IFERROR(VALUE(C19:C21),0)). It returns a correct number in the Function Arguments window when in the spreadsheet it shows #VALUE! error or respectively an incorrect sum.
I wonder if I am using the aforementioned functions wrong (can't IFERROR be used as an array here?), or is this some sort of an Excel bug (why the assessed value is different from the result in the spreadsheet?).
Thanks in advance for your comments and suggesting a solution.

Your formula :
=SUMPRODUCT(IFERROR(VALUE($C1:$C4),0),--($D1:$D4="yes"),--NOT(ISERROR($C$1:$C$4+1-1)),--(($C1:$C4)<>""))
and
=SUMPRODUCT(IFERROR(VALUE(C19:C21),0))
all need to be confirmed with Ctrl+Shift+Enter
Another option,
Change your formula into :
=SUMPRODUCT(N(+$C1:$C4),--($D1:$D4="yes"),--NOT(ISERROR($C$1:$C$4+1-1)),--(($C1:$C4)<>""))
and
=SUMPRODUCT(N(+C19:C21))
the change using N(+.... instead of IFERROR(VALUE(....
also, the above 2 formulas need not array entry

Related

Excel percentage column's empty cells gives value error

I wrote a if function for to see growing percentage in excel which one of the empty cell gives me an value error. That cells formula is like this;
=IF(AND(Z4=0,D4=0),0,IF(AND(Z4=0,D4>0),1,IF(AND(Z4=0,D4<0),-1,(D4-Z4)/ABS(Z4))))
I would like to see thise cells empty. Does anyone know this? Thanks!
Not entirely related to your current situation but try reducing your nested IFs with the SIGN function.
=if(z4=0, sign(d4), (d4-z4)/abs(z4))
Now related to your current situation, it would appear you have zero-length strings left by formulas that appear blank but are not equal to zero and cannot be used in a maths equation without producing a #VALUE! error.
You cannot use the VALUE(...) or INT(...) function to convert the zero-length strings to zero but you can use SUM(...).
=if(sum(z4)=0, sign(d4), (d4-z4)/abs(z4))
Alternately, you can default any formula returning an error with IFERROR.
=iferror(if(z4=0, sign(d4), (d4-z4)/abs(z4)), "")

Excel: Sumproduct not working when blanks in data set

I am trying to get a sumproduct function to average a column based on criteria in prior adjacent columns.
The column i am trying to average is calculated from a formula that has an IFERROR to return a blank if there is an error.
=IFERROR(A5*B3,"")
some of the cells in that column containt the blank generated by the if error statement, my sumproduct is giving a #value error when it tries to average the range with the blank. I want it treated as nothing not as 0
Is there anyway around this or should I try to recreate my sumproduct using some sort of averageifs function?
This is the sumproduct in question:
=SUMPRODUCT((Data!$KM$7:$OV$7=C$7)*(Data!$KM$9:$OV$118>=$B10)*(Data!$KM$9:$OV$118<=$A10)*(Data!$BLW$9:$BLW$118))/SUMPRODUCT((Data!$KM$7:$OV$7=C$7)*(Data!$KM$9:$OV$118>=$B10)*(Data!$KM$9:$OV$118<=$A10))
Try this array formula instead:
=AVERAGE(IF((Data!$KM$7:$OV$7=C$7)*(Data!$KM$9:$OV$118>=$B10)*(Data!$KM$9:$OV$118<=$A10)*(Data!$BLW$9:$BLW$118<>""),Data!$BLW$9:$BLW$118))
Being an array it needs to be confirmed with Ctrl-Shift-Enter when leaving edit mode. If done properly excel will put {} around the formula.
The reason SUMPRODUCT will not work is it tries to multiply a string, albeit an empty string but a string none the less, with numbers, which will throw an error.
The array formula ignores all the empty string cells and skips them.
The formula =IFERROR(A5*B3,"") puts a "" in the cell. This is not a value, so formulas using this cell won't work. You need to turn it to a numeric value even though it is blank
Use =value(IFERROR(A5*B3,""))
=SUMPRODUCT(P10,M10,L14,L13). This could be easy. We have to write what we want to do rather it is sum, product, division or subtract

Excel Find the max length of characters after decimal in a given column

I'm trying to find a way to get the max number of characters after the decimal place in a given column. For example
I found this to get the max length in a column (using ctrl+shift+enter):
=MAX(LEN(A1:A5))
And this formula to get the number of characters after the decimal for a single cell:
=LEN(A1)-FIND(".",A1)
But I need to combine the two into a single formula so that I don't need another column of data. Is this possible without VBA?
Edit, one example I might encounter would be 99.999 vs 100.12 that I'd need to differentiate between and result in a length of 3 characters after the decimal.
If any of your data is the result of formulas, you may have some surprising results and need to use VBA. Otherwise, so long as the format is General, you can use
=MAX(LEN(A1:A5)-FIND(".",A1:A5&"."),0)
confirmed by holding down ctrl+shift while hitting enter
You can use Array Formulas in conjunction with some of your original suggestions to accomplish this. The formula in the example you provided would be:
{=MAX(IFERROR(LEN(B1:B3)-FIND(".",B1:B3),0))}
Some notes:
The "IFERROR" function is used to return a 0 to the MAX function if the "." is not found in the string
Array formulas can be entered into excel by entering the text "=MAX(IFERROR(LEN(B1:B3)-FIND(".",B1:B3),0))" into the formula bar and pressing ctrl+shift+enter (at which point the curly brackets will appear)
Applying this formula should yeild the following results for your sample inputs:
Sample Results

Multiple HLOOKUP summation and being able accounting for "" in one of the results

I have a matrix setup where I am using multiple HLOOKUPS in a cell to derive a result. Due to some of the source data having blank cells, the HLOOKUP results in a #VALUE! error if any of the results lookup on a blank cell. I cannot use the IFERROR function because that will negate the addition and result in the entire formula deriving a blank result when in reality a summation of numbers should result (but because of the occurence of even one blank instance, the formula does not work). The way the spreadsheet is setup, I cannot change the source data to have zero in the blank cells, even though this would essentially solve the issue in a different way. Please see the example:
(HLOOKUP(L$1&"zzz.",Formula!$1:$34,$T5,FALSE)+HLOOKUP(L$1&"yyy",Formula!$1:$34,$T5,FALSE)+HLOOKUP(L$1&"uuu",Formula!$1:$34,$T5,FALSE)+HLOOKUP(L$1&"ppp",Formula!$1:$34,$T5,FALSE)+HLOOKUP(L$1&"ccc",Formula!$1:$34,$T5,FALSE)+HLOOKUP(L$1&"ddd",Formula!$1:$34,$T5,FALSE)
Any suggestions are greatly appreciated.
Your formula can be re-written in a different and more efficient way, viz:
=SUM(SUMIF(Formula!$1:$1,L$1&{"zzz.","yyy","uuu","ppp","ccc","ddd"},INDEX(Formula!$1:$34,$T5,)))
which also has the benefit that any search values which are not found do not cause the formula to error.
Even better would be to put those six search strings in the actual worksheet somewhere, e.g. A1:A6, in which case the above becomes the even-more succinct:
=SUMPRODUCT(SUMIF(Formula!$1:$1,L$1&$A$1:$A$6,INDEX(Formula!$1:$34,$T5,)))
Regards

ROW() function behaves differently inside SUM() and SUMPRODUCT()

Problem definition:
Enter any number in cell A1. Now try the following formulae anywhere on first row.
=SUM(INDIRECT("A"&ROW()))
and
=SUMPRODUCT(INDIRECT("A"&ROW()))
The first formula evaluates, the second one gives a #VALUE error.
This is caused by the ROW() function behaving differently inside SUMPRODUCT().
In the first formula, ROW() returns 1. In the second formula, row returns {1} (array of one length), even though the formula has not been entered as a CSE formula.
Why does this happen?
Background
I need to evaluate a formula of the type
=SUMPRODUCT(INDIRECT(*range formed by concatenation and using ROW()*)>1)
This is working out to an error. As a workaround to this issue, I now calculate ROW() in another cell (in the same row, obviously) and concatenate that inside my INDIRECT(). Alternately, I also have tried encapsulating it inside a sum function, like SUM(ROW()), and that works as well.
I would sure appreciate it if someone could explain (or point me to a resource that can explain) why ROW() returns an array inside SUMPRODUCT() without being CSE entered.
Interesting question. There are subtle issues here which I haven't seen documented.
It seems INDIRECT("A"&ROW()) returns an array consisting of one element which is a reference to a cell - not the value in that cell. Many functions cannot resolve this type of data correctly but a few functions such as N and T can "dereference" the array and return the underlying value.
Take this case where there are two elements in the array:
=SUM(N(INDIRECT("A"&ROW(1:2))))
This returns A1+A2 when array entered but it only returns A1 when entered normally. However changing ROW(1:2) to {1;2} in this formula returns the correct result when entered normally. The equivalent SUMPRODUCT formula returns A1+A2 whether array entered or not.
This may be related to how the arguments are registered in the function. According to http://msdn.microsoft.com/en-us/library/bb687900.aspx there are essentially two methods to register function arguments to handle Excel data types:
Type R/U: "Values, arrays, and range references."
Type P/Q: "Excel converts single-cell references to simple values and multi-cell references to arrays when preparing these arguments."
SUM arguments seem to conform with type R/U while SUMPRODUCT arguments behave like type P/Q. Array-entering the SUM formula above forces the range reference argument in ROW to be evaluated as an array whereas this happens automatically with SUMPRODUCT.
Update
After a little more investigation, here's further evidence that might support this theory. Based on the link in the comment, the formula =SUM((A1,A2)) gives the same values as:
?executeexcel4macro("CALL(""Xlcall32"",""Excel4"",""2JRJR"",4,,1,(!R1C1,!R2C1))")
Registering the last argument as type P by changing 2JRJR to 2JRJP gives an error in this case but does allow for single area ranges like !R1C1:!R2C1. On the other hand, changing the 4 (xlfsum) to 228 (xlfsumproduct) only allows single area references either way it's called just like SUMPRODUCT.
As ROW() returns an array, use INDEX to get the 1st element.
You example then becomes: =SUMPRODUCT(INDIRECT("A"&INDEX(ROW(),1)))
I don't think ROW() behaves differently here, it returns an array in both cases. I assume that SUM and SUMPRODUCT treat that array differently - not sure why.
Many functions or combinations of them return arrays - you don't need CTRL+SHIFT+ENTER to make that happen, you only need CSE in many cases to process the arrays created.
I would just use INDEX in place of INDIRECT (which also benefits you by avoiding a volatile function), i.e.
=SUMPRODUCT(INDEX(A:A,ROW()))
....expanding that to your range this formula will count the number of values > 1 in a range in column A where x defines the start row and y the end row
=COUNTIF(INDEX(A:A,x):INDEX(A:A,y),">1")
x and y can be calculated by formulas
you can use SUMPRODUCT or COUNTIFS in a similar way if there are more conditions to add

Resources